Skip to content

Commit 6f66667

Browse files
authored
perf: skip single_component_path_imports module walk when nothing to lint (#17225)
| crate | instructions base | instructions new | delta | |---|---|---|---| | cargo-0.80.0 (lib) | 29,895,121,178 | 29,874,691,083 | -0.068% | | cargo-0.80.0 (bin) | 1,632,148,485 | 1,630,985,360 | -0.071% | | wasmi-0.35.0 | 16,147,142,661 | 16,124,491,362 | -0.140% | | serde-1.0.204 | 7,203,885,789 | 7,198,196,376 | -0.079% | | ryu-1.0.18 | 271,121,817 | 270,416,802 | -0.260% | changelog: none
2 parents 6032abe + a972a88 commit 6f66667

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

clippy_lints/src/single_component_path_imports.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,24 @@ impl SingleComponentPathImports {
146146
// ```
147147
let mut macros = Vec::new();
148148

149-
let mut import_usage_visitor = ImportUsageVisitor::default();
150149
for item in items {
151150
self.track_uses(item, &mut imports_reused_with_self, &mut single_use_usages, &mut macros);
151+
}
152+
153+
// Only walk the module's AST in search of `self::xxx` paths when there are single
154+
// component imports left to lint, as the visitor recurses into every nested item.
155+
single_use_usages.retain(|usage| !imports_reused_with_self.contains(&usage.name));
156+
if single_use_usages.is_empty() {
157+
return;
158+
}
159+
160+
let mut import_usage_visitor = ImportUsageVisitor::default();
161+
for item in items {
152162
import_usage_visitor.visit_item(item);
153163
}
154164

155165
for usage in single_use_usages {
156-
if !imports_reused_with_self.contains(&usage.name)
157-
&& !import_usage_visitor.imports_referenced_with_self.contains(&usage.name)
158-
{
166+
if !import_usage_visitor.imports_referenced_with_self.contains(&usage.name) {
159167
self.found.entry(usage.item_id).or_default().push(usage);
160168
}
161169
}

0 commit comments

Comments
 (0)