mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
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>
This commit is contained in:
commit
145b51f9da
@ -136,10 +136,13 @@ impl Entry {
|
|||||||
impl Directories {
|
impl Directories {
|
||||||
/// Returns `true` if `path` is included in `self`.
|
/// Returns `true` if `path` is included in `self`.
|
||||||
pub fn contains_file(&self, path: &AbsPath) -> bool {
|
pub fn contains_file(&self, path: &AbsPath) -> bool {
|
||||||
|
// First, check the file extension...
|
||||||
let ext = path.extension().unwrap_or_default();
|
let ext = path.extension().unwrap_or_default();
|
||||||
if self.extensions.iter().all(|it| it.as_str() != ext) {
|
if self.extensions.iter().all(|it| it.as_str() != ext) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Then, check for path inclusion...
|
||||||
self.includes_path(path)
|
self.includes_path(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,25 +161,22 @@ impl Directories {
|
|||||||
/// - This path is longer than any element in `self.exclude` that is a prefix
|
/// - This path is longer than any element in `self.exclude` that is a prefix
|
||||||
/// of `path`. In case of equality, exclusion wins.
|
/// of `path`. In case of equality, exclusion wins.
|
||||||
fn includes_path(&self, path: &AbsPath) -> bool {
|
fn includes_path(&self, path: &AbsPath) -> bool {
|
||||||
let mut include: Option<&AbsPathBuf> = None;
|
let mut include = None::<&AbsPathBuf>;
|
||||||
for incl in &self.include {
|
for incl in &self.include {
|
||||||
if path.starts_with(incl) {
|
if path.starts_with(incl) {
|
||||||
include = Some(match include {
|
include = Some(match include {
|
||||||
Some(prev) if prev.starts_with(incl) => prev,
|
Some(prev) if prev.starts_with(incl) => prev,
|
||||||
_ => incl,
|
_ => incl,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let include = match include {
|
let include = match include {
|
||||||
Some(it) => it,
|
Some(it) => it,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
for excl in &self.exclude {
|
|
||||||
if path.starts_with(excl) && excl.starts_with(include) {
|
!self.exclude.iter().any(|excl| path.starts_with(excl) && excl.starts_with(include))
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user