Skip to content

Commit 7606f47

Browse files
Boshenclaude
andcommitted
perf(parser): avoid redundant IdentifierReference clone in shorthand property
Build `value` after handling `=`, and allocate a fresh `IdentifierReference` in each branch instead of cloning. Saves one clone per shorthand property. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9b4d9f6 commit 7606f47

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

crates/oxc_parser/src/js/object.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ impl<'a, C: Config> ParserImpl<'a, C> {
9898

9999
if is_shorthand_property_assignment {
100100
if let PropertyKey::StaticIdentifier(identifier_name) = key {
101-
let identifier_reference =
102-
self.ast.identifier_reference(identifier_name.span, identifier_name.name);
103-
let value = Expression::Identifier(self.alloc(identifier_reference.clone()));
104101
// CoverInitializedName ({ foo = bar })
105102
if self.eat(Kind::Eq) {
106103
let right = self.parse_assignment_expression_or_higher();
107104
let left = AssignmentTarget::AssignmentTargetIdentifier(
108-
self.alloc(identifier_reference),
105+
self.ast
106+
.alloc_identifier_reference(identifier_name.span, identifier_name.name),
109107
);
110108
let expr = self.ast.assignment_expression(
111109
self.end_span(span),
@@ -115,6 +113,9 @@ impl<'a, C: Config> ParserImpl<'a, C> {
115113
);
116114
self.state.cover_initialized_name.insert(span, expr);
117115
}
116+
let value = Expression::Identifier(
117+
self.ast.alloc_identifier_reference(identifier_name.span, identifier_name.name),
118+
);
118119
self.ast.alloc_object_property(
119120
self.end_span(span),
120121
PropertyKind::Init,

0 commit comments

Comments
 (0)