From 0765c9713b75230c643ca386b24080c8dba00a6e Mon Sep 17 00:00:00 2001 From: Basti Ortiz <39114273+Some-Dood@users.noreply.github.com> Date: Tue, 10 Aug 2021 15:56:16 +0800 Subject: [PATCH] Refactor: use `filter_map` when iterating over stored IDs and --- crates/vfs/src/lib.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/vfs/src/lib.rs b/crates/vfs/src/lib.rs index 7828e51be9..8404f1635f 100644 --- a/crates/vfs/src/lib.rs +++ b/crates/vfs/src/lib.rs @@ -139,13 +139,12 @@ impl Vfs { /// /// This will skip deleted files. pub fn iter(&self) -> impl Iterator + '_ { - (0..self.data.len()) - .map(|it| FileId(it as u32)) - .filter(move |&file_id| self.get(file_id).is_some()) - .map(move |file_id| { - let path = self.interner.lookup(file_id); - (file_id, path) - }) + (0..self.data.len()).filter_map(move |it| { + let file_id = FileId(it as u32); + let _ = self.get(file_id).as_ref()?; + let path = self.interner.lookup(file_id); + Some((file_id, path)) + }) } /// Update the `path` with the given `contents`. `None` means the file was deleted.