Skip to content

Commit a61a50b

Browse files
committed
refactor(isolated_declarations): do not store temp values in arena (oxc-project#9733)
`stmts` here is an `ArenaVec<&Statement>` (`&Statement` not `Statement`). This is a temporary collection, and doesn't end up in the AST, so we shouldn't store it in the arena. Use a `std::vec::Vec` instead of `oxc_allocator::Vec`. This should also remove some of the lifetime problems we have in oxc-project#9656. This change may cause a small perf hit, but in my view it's still a good change. If we want to get a speed boost, a better solution would be to have a temporary "scratch space" arena which we can allocate *all* temporary values into. This would likely give us a sizeable speed boost across many parts of Oxc (oxc-project/backlog#121).
1 parent 3943563 commit a61a50b

File tree

1 file changed

+15
-12
lines changed
  • crates/oxc_isolated_declarations/src

1 file changed

+15
-12
lines changed

crates/oxc_isolated_declarations/src/lib.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ impl<'a> IsolatedDeclarations<'a> {
148148
) -> ArenaVec<'a, Statement<'a>> {
149149
self.report_error_for_expando_function(stmts);
150150

151-
let mut stmts =
152-
self.ast.vec_from_iter(stmts.iter().filter(|stmt| {
153-
stmt.is_declaration() && !self.has_internal_annotation(stmt.span())
154-
}));
151+
let mut stmts = stmts
152+
.iter()
153+
.filter(|stmt| stmt.is_declaration() && !self.has_internal_annotation(stmt.span()))
154+
.collect::<Vec<_>>();
155155

156156
Self::remove_function_overloads_implementation(&mut stmts);
157157

@@ -170,10 +170,13 @@ impl<'a> IsolatedDeclarations<'a> {
170170
) -> ArenaVec<'a, Statement<'a>> {
171171
self.report_error_for_expando_function(stmts);
172172

173-
let mut stmts = self.ast.vec_from_iter(stmts.iter().filter(|stmt| {
174-
(stmt.is_declaration() || stmt.is_module_declaration())
175-
&& !self.has_internal_annotation(stmt.span())
176-
}));
173+
let mut stmts = stmts
174+
.iter()
175+
.filter(|stmt| {
176+
(stmt.is_declaration() || stmt.is_module_declaration())
177+
&& !self.has_internal_annotation(stmt.span())
178+
})
179+
.collect::<Vec<_>>();
177180
Self::remove_function_overloads_implementation(&mut stmts);
178181

179182
// https://github.com/microsoft/TypeScript/pull/58912
@@ -364,7 +367,7 @@ impl<'a> IsolatedDeclarations<'a> {
364367
+ usize::from(extra_export_var_statement.is_some())
365368
+ usize::from(need_empty_export_marker),
366369
);
367-
stmts.iter().for_each(|stmt| {
370+
for stmt in stmts {
368371
if transformed_spans.contains(&stmt.span()) {
369372
let new_stmt = transformed_stmts
370373
.remove(&stmt.span())
@@ -378,7 +381,7 @@ impl<'a> IsolatedDeclarations<'a> {
378381
}
379382
}
380383
new_stmts.push(new_stmt);
381-
return;
384+
continue;
382385
}
383386
match stmt {
384387
Statement::ImportDeclaration(decl) => {
@@ -409,7 +412,7 @@ impl<'a> IsolatedDeclarations<'a> {
409412
}
410413
_ => {}
411414
}
412-
});
415+
}
413416

414417
if need_empty_export_marker {
415418
let specifiers = self.ast.vec();
@@ -427,7 +430,7 @@ impl<'a> IsolatedDeclarations<'a> {
427430
new_stmts
428431
}
429432

430-
fn remove_function_overloads_implementation(stmts: &mut ArenaVec<'a, &Statement<'a>>) {
433+
fn remove_function_overloads_implementation(stmts: &mut Vec<&Statement<'a>>) {
431434
let mut last_function_name: Option<Atom<'a>> = None;
432435
let mut is_export_default_function_overloads = false;
433436

0 commit comments

Comments
 (0)