Refactor: use filter_map when iterating over stored IDs and

This commit is contained in:
Basti Ortiz 2021-08-10 15:56:16 +08:00
parent e912d6507f
commit 0765c9713b
No known key found for this signature in database
GPG key ID: 1402D5CB17F48E1B

View file

@ -139,13 +139,12 @@ impl Vfs {
/// ///
/// This will skip deleted files. /// This will skip deleted files.
pub fn iter(&self) -> impl Iterator<Item = (FileId, &VfsPath)> + '_ { pub fn iter(&self) -> impl Iterator<Item = (FileId, &VfsPath)> + '_ {
(0..self.data.len()) (0..self.data.len()).filter_map(move |it| {
.map(|it| FileId(it as u32)) let file_id = FileId(it as u32);
.filter(move |&file_id| self.get(file_id).is_some()) let _ = self.get(file_id).as_ref()?;
.map(move |file_id| { let path = self.interner.lookup(file_id);
let path = self.interner.lookup(file_id); Some((file_id, path))
(file_id, path) })
})
} }
/// Update the `path` with the given `contents`. `None` means the file was deleted. /// Update the `path` with the given `contents`. `None` means the file was deleted.