Slightly better ICACHE hits

This commit is contained in:
2022-12-09 09:20:34 +01:00
parent 951ed73024
commit bbfa367775

View File

@@ -70,6 +70,11 @@ fn scenery<'a>(
tree_stack.clear(); tree_stack.clear();
for (i, (&val, score)) in values.into_iter().zip(visible).enumerate() { for (i, (&val, score)) in values.into_iter().zip(visible).enumerate() {
scenery_helper(i, tree_stack, val, score);
}
}
fn scenery_helper(i: usize, tree_stack: &mut Vec<(usize, u8)>, val: u8, score: &mut usize) {
if i > 0 { if i > 0 {
let mut first = 0; let mut first = 0;
@@ -94,7 +99,6 @@ fn scenery<'a>(
} else { } else {
*score = 0; *score = 0;
} }
}
} }
pub fn part2(input: &[u8]) -> Result<String> { pub fn part2(input: &[u8]) -> Result<String> {
@@ -106,7 +110,7 @@ pub fn part2(input: &[u8]) -> Result<String> {
let mut score = vec![1; width * height]; let mut score = vec![1; width * height];
let mut tree_stack = Vec::new(); let mut tree_stack = Vec::with_capacity(10);
// Horizontal striping // Horizontal striping
for (y, row) in input.chunks_exact(width + 1).enumerate() { for (y, row) in input.chunks_exact(width + 1).enumerate() {