Skip to content

Commit 09ae2a9

Browse files
authored
perf(linter): Eliminate unnecessary Iterator::collect() allocations (oxc-project#12776)
1 parent 21adcd2 commit 09ae2a9

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

crates/oxc_linter/src/rules/react/exhaustive_deps.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,6 @@ impl Rule for ExhaustiveDeps {
590590

591591
// effects are allowed to have extra dependencies
592592
if !is_effect {
593-
let unnecessary_deps: Vec<_> =
594-
declared_dependencies.difference(&found_dependencies).collect();
595-
596593
// lastly, we need co compare for any unnecessary deps
597594
// for example if `props.foo`, AND `props.foo.bar.baz` was declared in the deps array
598595
// `props.foo.bar.baz` is unnecessary (already covered by `props.foo`)
@@ -612,7 +609,7 @@ impl Rule for ExhaustiveDeps {
612609
}
613610
});
614611

615-
for dep in unnecessary_deps {
612+
for dep in declared_dependencies.difference(&found_dependencies) {
616613
if found_dependencies.iter().any(|found_dep| found_dep.contains(dep)) {
617614
continue;
618615
}

crates/oxc_semantic/examples/cfg.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,16 @@ fn main() -> std::io::Result<()> {
139139
},
140140
&|_graph, node| {
141141
let nodes = ast_nodes_by_block.get(node.1).map_or("None".to_string(), |nodes| {
142-
let nodes: Vec<_> =
143-
nodes.iter().map(|node| format!("{}", node.kind().debug_name())).collect();
144142
if nodes.len() > 1 {
145143
format!(
146144
"{}\\l",
147-
nodes.into_iter().map(|it| format!("\\l {it}")).join("")
145+
nodes
146+
.iter()
147+
.map(|node| format!("\\l {}", node.kind().debug_name()))
148+
.join("")
148149
)
149150
} else {
150-
nodes.into_iter().join("")
151+
nodes.iter().map(|node| format!("{}", node.kind().debug_name())).join("")
151152
}
152153
});
153154
format!(

0 commit comments

Comments
 (0)