From 27605b402e5009d03bd1c961c6272b8d2dbe674d Mon Sep 17 00:00:00 2001 From: Basti Ortiz <39114273+Some-Dood@users.noreply.github.com> Date: Tue, 10 Aug 2021 22:40:04 +0800 Subject: [PATCH] Fix: prefer the usage of `for` loops over `fold` --- crates/vfs/src/loader.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/vfs/src/loader.rs b/crates/vfs/src/loader.rs index 5959ce2ce7..c341b974a0 100644 --- a/crates/vfs/src/loader.rs +++ b/crates/vfs/src/loader.rs @@ -161,16 +161,15 @@ impl Directories { /// - This path is longer than any element in `self.exclude` that is a prefix /// of `path`. In case of equality, exclusion wins. fn includes_path(&self, path: &AbsPath) -> bool { - let include = self.include.iter().fold(None::<&AbsPathBuf>, |include, incl| { - if !path.starts_with(incl) { - return include; + let mut include = None::<&AbsPathBuf>; + for incl in &self.include { + if path.starts_with(incl) { + include = Some(match include { + Some(prev) if prev.starts_with(incl) => prev, + _ => incl, + }); } - - Some(match include { - Some(prev) if prev.starts_with(incl) => prev, - _ => incl, - }) - }); + } let include = match include { Some(it) => it,