From be535e28cf7da89a5c92f5f54d099dba4602dfde Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 29 Jul 2020 09:42:20 +1000 Subject: [PATCH] refactor: Avoid unnecessary uses of `enumerate()`. --- src/util/argstr.rs | 10 +--------- src/util/graph.rs | 7 +------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/util/argstr.rs b/src/util/argstr.rs index c12f141b..e98c3c39 100644 --- a/src/util/argstr.rs +++ b/src/util/argstr.rs @@ -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 } diff --git a/src/util/graph.rs b/src/util/graph.rs index 183b2d9d..c0156332 100644 --- a/src/util/graph.rs +++ b/src/util/graph.rs @@ -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() } }