Skip to content

Commit 145b51f

Browse files
bors[bot]BastiDood
andauthored
Merge #9836
9836: Refactor: quick clean-up of iteration idioms in the `vfs` crate r=matklad a=Some-Dood This PR cleans up some of the iteration idioms used in the `vfs` crate. Most of the changes simply converted `for` loops into their `std::iter::Iterator`-method counterpart. Other changes required some inversion of logic to accommodate for better short-circuiting. Overall, there should be no behavioral changes. If there are any stylistic issues, I will gladly adhere to them and adjust the PR accordingly. Thanks! Co-authored-by: Basti Ortiz <39114273+Some-Dood@users.noreply.github.com>
2 parents 6c80c42 + 0986632 commit 145b51f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crates/vfs/src/loader.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ impl Entry {
136136
impl Directories {
137137
/// Returns `true` if `path` is included in `self`.
138138
pub fn contains_file(&self, path: &AbsPath) -> bool {
139+
// First, check the file extension...
139140
let ext = path.extension().unwrap_or_default();
140141
if self.extensions.iter().all(|it| it.as_str() != ext) {
141142
return false;
142143
}
144+
145+
// Then, check for path inclusion...
143146
self.includes_path(path)
144147
}
145148

@@ -158,25 +161,22 @@ impl Directories {
158161
/// - This path is longer than any element in `self.exclude` that is a prefix
159162
/// of `path`. In case of equality, exclusion wins.
160163
fn includes_path(&self, path: &AbsPath) -> bool {
161-
let mut include: Option<&AbsPathBuf> = None;
164+
let mut include = None::<&AbsPathBuf>;
162165
for incl in &self.include {
163166
if path.starts_with(incl) {
164167
include = Some(match include {
165168
Some(prev) if prev.starts_with(incl) => prev,
166169
_ => incl,
167-
})
170+
});
168171
}
169172
}
173+
170174
let include = match include {
171175
Some(it) => it,
172176
None => return false,
173177
};
174-
for excl in &self.exclude {
175-
if path.starts_with(excl) && excl.starts_with(include) {
176-
return false;
177-
}
178-
}
179-
true
178+
179+
!self.exclude.iter().any(|excl| path.starts_with(excl) && excl.starts_with(include))
180180
}
181181
}
182182

0 commit comments

Comments
 (0)