2021 day8/rust: make v4 function unsafe

This commit is contained in:
Xiretza 2021-12-09 21:26:36 +01:00
parent 591cde8631
commit 07a1391030
3 changed files with 7 additions and 3 deletions

View file

@ -36,7 +36,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
group.bench_function("v4", |b| {
b.iter(|| {
for line in &lines {
let _ = v4::unscramble(black_box(line));
let _ = unsafe { v4::unscramble(black_box(line)) };
}
})
});

View file

@ -17,7 +17,7 @@ const FREQ_TABLE: [usize; 256] = {
#[must_use]
#[inline]
pub fn unscramble(line: &str) -> LineResult {
pub unsafe fn unscramble(line: &str) -> LineResult {
let mut bytes = line.bytes();
let mut counts = [0; 7];

View file

@ -73,5 +73,9 @@ pub fn test_unscramble_v3() {
#[test]
pub fn test_unscramble_v4() {
test_unscramble(v4::unscramble)
fn safe_v4(input: &str) -> LineResult {
unsafe { v4::unscramble(input) }
}
test_unscramble(safe_v4)
}