refactor: Avoid unnecessary uses of enumerate().

This commit is contained in:
Nicholas Nethercote 2020-07-29 09:42:20 +10:00
parent d8c775eb26
commit be535e28cf
2 changed files with 2 additions and 15 deletions

View file

@ -76,15 +76,7 @@ impl<'a> ArgStr<'a> {
pub(crate) fn trim_start_n_matches(&self, n: usize, ch: u8) -> ArgStr {
assert!(ch.is_ascii());
let i = self
.0
.iter()
.take(n)
.take_while(|c| **c == ch)
.enumerate()
.last()
.map(|(i, _)| i + 1)
.unwrap_or(0);
let i = self.0.iter().take(n).take_while(|c| **c == ch).count();
self.split_at_unchecked(i).1
}

View file

@ -30,12 +30,7 @@ where
self.0.push(Child::new(req));
idx
} else {
self.0
.iter()
.enumerate()
.find(|(_, e)| e.id == req)
.map(|(i, _)| i)
.unwrap()
self.0.iter().position(|e| e.id == req).unwrap()
}
}