mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
refactor(transformer/class-properties): re-use existing Vec (#7854)
Follow-on after #7831. Previously this code was: 1. Create a new empty `Vec` (in `move_vec` call). 2. Consume the old `Vec` and create a new `Vec<ArrayExpressionElement>`. 3. Push to the empty `Vec` created in step 1. Instead: 1. Drain the old `Vec` and create a new `Vec<ArrayExpressionElement>`. 2. The old `Vec` is now empty, but still holds an allocation if it wasn't empty before. 3. Push to the old `Vec` (re-using the existing allocation). i.e. We create 1 less `Vec`, and re-use an existing allocation if possible.
This commit is contained in:
parent
1380b7b7e9
commit
eb47d433ff
1 changed files with 2 additions and 3 deletions
|
|
@ -98,9 +98,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
|
|||
arguments: &mut ArenaVec<'a, Argument<'a>>,
|
||||
ctx: &mut TraverseCtx<'a>,
|
||||
) {
|
||||
let owned_arguments = ctx.ast.move_vec(arguments);
|
||||
let elements =
|
||||
ctx.ast.vec_from_iter(owned_arguments.into_iter().map(ArrayExpressionElement::from));
|
||||
let elements = arguments.drain(..).map(ArrayExpressionElement::from);
|
||||
let elements = ctx.ast.vec_from_iter(elements);
|
||||
let array = ctx.ast.expression_array(SPAN, elements, None);
|
||||
arguments.push(Argument::from(array));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue