Refactor package_roots for readability. (#10543)

This commit is contained in:
Alexey Preobrazhenskiy 2024-03-24 13:02:30 +01:00 committed by GitHub
parent c447454111
commit 7cc40d5621
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,21 +180,14 @@ impl<'a> Resolver<'a> {
let mut package_roots: FxHashMap<&Path, Option<&Path>> = FxHashMap::default();
for file in files {
if let Some(package) = file.parent() {
match package_roots.entry(package) {
std::collections::hash_map::Entry::Occupied(_) => continue,
std::collections::hash_map::Entry::Vacant(entry) => {
let namespace_packages = if has_namespace_packages {
self.resolve(file).linter.namespace_packages.as_slice()
} else {
&[]
};
entry.insert(detect_package_root_with_cache(
package,
namespace_packages,
&mut package_cache,
));
}
}
package_roots.entry(package).or_insert_with(|| {
let namespace_packages = if has_namespace_packages {
self.resolve(file).linter.namespace_packages.as_slice()
} else {
&[]
};
detect_package_root_with_cache(package, namespace_packages, &mut package_cache)
});
}
}