Created
          October 25, 2018 09:04 
        
      - 
      
- 
        Save MaikKlein/799110a030e474cf353de5bd4b5a16fb to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | 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