Created
December 10, 2022 22:04
-
-
Save Cykooz/c38f3dd59cfcf43f103496ab8b6580a2 to your computer and use it in GitHub Desktop.
Process data from iterator with pre-readming.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Pre-reading data from memory increases speed slightly for some operations | |
#[inline(always)] | |
fn foreach_with_pre_reading<D, I>( | |
mut iter: impl Iterator<Item = I>, | |
mut read_data: impl FnMut(I) -> D, | |
mut process_data: impl FnMut(D), | |
) { | |
let mut next_data: D; | |
if let Some(src) = iter.next() { | |
next_data = read_data(src); | |
for src in iter { | |
let data = next_data; | |
next_data = read_data(src); | |
process_data(data); | |
} | |
process_data(next_data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment