Skip to content

Instantly share code, notes, and snippets.

@MaikKlein
Created October 25, 2018 09:04
Show Gist options
  • Save MaikKlein/799110a030e474cf353de5bd4b5a16fb to your computer and use it in GitHub Desktop.
Save MaikKlein/799110a030e474cf353de5bd4b5a16fb to your computer and use it in GitHub Desktop.
pub struct MatchIter<'s, S, I> {
world: &'s World<S>,
iter: I,
}
impl<'s, S, I> Iterator for MatchIter<'s, S, I>
where
I: Iterator,
{
type Item = I::Item;
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
#[inline]
fn next(&mut self) -> Option<Self::Item> {
self.iter.next()
}
}
...
pub fn matcher<'s, Q>(
&'s self,
) -> impl Iterator<...> + 's {
let iter = unsafe {
self.storages
.iter()
.filter(|&storage| Q::is_match(storage))
.map(|storage| Q::query(storage))
.flat_map(|iter| iter)
};
iter // <= fast
//MatchIter { world: self, iter } // <= 3x slower
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment