mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(minifier): use ReplaceWith instead of TakeIn (#24017)
Replace `take_in` with `replace_with` in as many places as possible in minifier. See #24012 for explanation of the advantage of `replace_with`. Likely we could use `replace_with` in many more places, if we adapted the methods through which most replacement operations flow (which also track "dirty" state). I've left this for now, as I don't really understand the minifier.
This commit is contained in:
1 parent
6ab439a902
commit
b227a069a5
2 files changed
+21
-18
No files matched your search
@@ -1,5 +1,5 @@
|
||||
use crate::generated::ancestor::Ancestor;
|
||||
use oxc_allocator::{ArenaVec, TakeIn};
|
||||
use oxc_allocator::{ArenaVec, ReplaceWith, TakeIn};
|
||||
use oxc_ast::ast::*;
|
||||
use oxc_ecmascript::{
|
||||
constant_evaluation::{DetermineValueType, ValueType},
|
||||
@@ -205,18 +205,21 @@ impl<'a> Normalize {
|
||||
}
|
||||
|
||||
fn convert_while_to_for(stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
|
||||
let Statement::WhileStatement(while_stmt) = stmt.take_in(ctx) else { return };
|
||||
let while_stmt = while_stmt.unbox();
|
||||
let for_stmt = ForStatement::boxed_with_scope_id(
|
||||
while_stmt.span,
|
||||
None,
|
||||
Some(while_stmt.test),
|
||||
None,
|
||||
while_stmt.body,
|
||||
ctx.create_child_scope_of_current(ScopeFlags::empty()),
|
||||
ctx,
|
||||
);
|
||||
*stmt = Statement::ForStatement(for_stmt);
|
||||
// Caller (`exit_statement`) only calls this for a `WhileStatement`, so the `else` is dead.
|
||||
stmt.replace_with(|stmt| {
|
||||
let Statement::WhileStatement(while_stmt) = stmt else { unreachable!() };
|
||||
let while_stmt = while_stmt.unbox();
|
||||
let for_stmt = ForStatement::boxed_with_scope_id(
|
||||
while_stmt.span,
|
||||
None,
|
||||
Some(while_stmt.test),
|
||||
None,
|
||||
while_stmt.body,
|
||||
ctx.create_child_scope_of_current(ScopeFlags::empty()),
|
||||
ctx,
|
||||
);
|
||||
Statement::ForStatement(for_stmt)
|
||||
});
|
||||
}
|
||||
|
||||
fn convert_const_to_let(decl: &mut VariableDeclaration<'a>, ctx: &TraverseCtx<'a>) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
File | File size || Sys allocs | Sys reallocs || Arena allocs | Arena reallocs
|
||||
---------------------------------------------------------------------------------------------------------------------------
|
||||
checker.ts | 2.92 MB || 155 | 5 || 152822 | 28253
|
||||
checker.ts | 2.92 MB || 155 | 5 || 152755 | 28253
|
||||
|
||||
App.tsx | 415.34 kB || 63 | 8 || 17028 | 2702
|
||||
|
||||
RadixUIAdoptionSection.jsx | 2.52 kB || 21 | 0 || 32 | 6
|
||||
|
||||
pdf.mjs | 567.30 kB || 2469 | 205 || 47489 | 7742
|
||||
pdf.mjs | 567.30 kB || 2469 | 205 || 47471 | 7742
|
||||
|
||||
antd.js | 6.69 MB || 1044 | 56 || 372682 | 76751
|
||||
antd.js | 6.69 MB || 1044 | 56 || 372637 | 76751
|
||||
|
||||
binder.ts | 193.08 kB || 33 | 1 || 7084 | 824
|
||||
binder.ts | 193.08 kB || 33 | 1 || 7076 | 824
|
||||
|
||||
kitchen-sink.tsx | 732.90 kB || 2298 | 174 || 88070 | 15654
|
||||
kitchen-sink.tsx | 732.90 kB || 2298 | 174 || 87997 | 15654
|
||||
|
||||
Reference in new issue
Block a user