2021 day8/rust: make v4 function unsafe
This commit is contained in:
parent
591cde8631
commit
07a1391030
3 changed files with 7 additions and 3 deletions
|
@ -36,7 +36,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||||
group.bench_function("v4", |b| {
|
group.bench_function("v4", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
for line in &lines {
|
for line in &lines {
|
||||||
let _ = v4::unscramble(black_box(line));
|
let _ = unsafe { v4::unscramble(black_box(line)) };
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,7 @@ const FREQ_TABLE: [usize; 256] = {
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn unscramble(line: &str) -> LineResult {
|
pub unsafe fn unscramble(line: &str) -> LineResult {
|
||||||
let mut bytes = line.bytes();
|
let mut bytes = line.bytes();
|
||||||
|
|
||||||
let mut counts = [0; 7];
|
let mut counts = [0; 7];
|
||||||
|
|
|
@ -73,5 +73,9 @@ pub fn test_unscramble_v3() {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_unscramble_v4() {
|
pub fn test_unscramble_v4() {
|
||||||
test_unscramble(v4::unscramble)
|
fn safe_v4(input: &str) -> LineResult {
|
||||||
|
unsafe { v4::unscramble(input) }
|
||||||
|
}
|
||||||
|
|
||||||
|
test_unscramble(safe_v4)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue