day5: performance: don't iterate to position just do arithemtic
This commit is contained in:
		@@ -163,10 +163,7 @@ impl From<&str> for AlmanacMapping {
 | 
				
			|||||||
impl AlmanacMapping {
 | 
					impl AlmanacMapping {
 | 
				
			||||||
    fn lookup(&self, key: u64) -> Option<u64> {
 | 
					    fn lookup(&self, key: u64) -> Option<u64> {
 | 
				
			||||||
        if self.source_range.contains(&key) {
 | 
					        if self.source_range.contains(&key) {
 | 
				
			||||||
            match self.source_range.clone().position(|x| x == key) {
 | 
					            Some(self.dest_range.start + (key - self.source_range.start))
 | 
				
			||||||
                Some(i) => self.dest_range.clone().nth(i),
 | 
					 | 
				
			||||||
                None => None,
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            None
 | 
					            None
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user