Skip to content

Commit eb47d43

Browse files
committed
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.
1 parent 1380b7b commit eb47d43

File tree

1 file changed

+2
-3
lines changed
  • crates/oxc_transformer/src/es2022/class_properties

1 file changed

+2
-3
lines changed

crates/oxc_transformer/src/es2022/class_properties/supers.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
9898
arguments: &mut ArenaVec<'a, Argument<'a>>,
9999
ctx: &mut TraverseCtx<'a>,
100100
) {
101-
let owned_arguments = ctx.ast.move_vec(arguments);
102-
let elements =
103-
ctx.ast.vec_from_iter(owned_arguments.into_iter().map(ArrayExpressionElement::from));
101+
let elements = arguments.drain(..).map(ArrayExpressionElement::from);
102+
let elements = ctx.ast.vec_from_iter(elements);
104103
let array = ctx.ast.expression_array(SPAN, elements, None);
105104
arguments.push(Argument::from(array));
106105
}

0 commit comments

Comments
 (0)