Skip to content

Instantly share code, notes, and snippets.

@asd142513
Created December 22, 2023 06:05
Show Gist options
  • Save asd142513/2409db24028a9db50391e1ce9f49b855 to your computer and use it in GitHub Desktop.
Save asd142513/2409db24028a9db50391e1ce9f49b855 to your computer and use it in GitHub Desktop.
black box
impl State {
fn new(valves: &[Valve]) -> Self {
// let valve_states = black_box(valves)
// .iter()
// .map(|valve| valve.rate == 0)
// .collect();
let mut valve_states = Vec::with_capacity(black_box(valves).len()); // Fast
for valve in valves {
valve_states.push(black_box(valve).rate == 0);
}
let valve_states = black_box(valve_states);
State {
valve_states,
position: 0,
rate: 0,
released_pressure: 0,
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment