Skip to content

Commit 0765c97

Browse files
committed
Refactor: use filter_map when iterating over stored IDs and
1 parent e912d65 commit 0765c97

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

crates/vfs/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,12 @@ impl Vfs {
139139
///
140140
/// This will skip deleted files.
141141
pub fn iter(&self) -> impl Iterator<Item = (FileId, &VfsPath)> + '_ {
142-
(0..self.data.len())
143-
.map(|it| FileId(it as u32))
144-
.filter(move |&file_id| self.get(file_id).is_some())
145-
.map(move |file_id| {
146-
let path = self.interner.lookup(file_id);
147-
(file_id, path)
148-
})
142+
(0..self.data.len()).filter_map(move |it| {
143+
let file_id = FileId(it as u32);
144+
let _ = self.get(file_id).as_ref()?;
145+
let path = self.interner.lookup(file_id);
146+
Some((file_id, path))
147+
})
149148
}
150149

151150
/// Update the `path` with the given `contents`. `None` means the file was deleted.

0 commit comments

Comments
 (0)