Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(es/resolver): Remove needless allocations #10120

Merged
merged 2 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fifty-grapes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: minor
swc_ecma_transforms_base: minor
---

perf: remove needless collect in resolver
51 changes: 21 additions & 30 deletions crates/swc_ecma_transforms_base/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1957,39 +1957,30 @@ impl VisitMut for Hoister<'_, '_> {
/// that there is already an global declaration of Ic when deal with the try
/// block.
fn visit_mut_module_items(&mut self, items: &mut Vec<ModuleItem>) {
let others = items
.iter_mut()
.filter_map(|item| match item {
ModuleItem::Stmt(Stmt::Decl(Decl::Var(v)))
| ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
decl: Decl::Var(v),
..
})) if matches!(
&**v,
VarDecl {
kind: VarDeclKind::Var,
..
}
) =>
{
item.visit_mut_with(self);
None
}

ModuleItem::Stmt(Stmt::Decl(Decl::Fn(..)))
| ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
decl: Decl::Fn(..),
items.iter_mut().for_each(|item| match item {
ModuleItem::Stmt(Stmt::Decl(Decl::Var(v)))
| ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
decl: Decl::Var(v),
..
})) if matches!(
&**v,
VarDecl {
kind: VarDeclKind::Var,
..
})) => {
item.visit_mut_with(self);
None
}
_ => Some(item),
})
.collect::<Vec<_>>();
) =>
{
item.visit_mut_with(self);
}

others.into_iter().for_each(|item| {
item.visit_mut_with(self);
ModuleItem::Stmt(Stmt::Decl(Decl::Fn(..)))
| ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
decl: Decl::Fn(..),
..
})) => {
item.visit_mut_with(self);
}
_ => item.visit_mut_with(self),
});
}

Expand Down
Loading