From c0dd3f8e32f233d069ca0be08108bc8d8c0262df Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 20 Dec 2024 03:10:23 +0000 Subject: [PATCH] perf(ast): `move_expression` and `move_statement` produce dummy with no span (#7995) The purpose of `AstBuilder::move_*` methods is to create dummy nodes which will later be replaced again. Give the dummy nodes empty spans as it's faster, and no point in them having a real span. --- crates/oxc_ast/src/ast_builder_impl.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/oxc_ast/src/ast_builder_impl.rs b/crates/oxc_ast/src/ast_builder_impl.rs index 7ea077656..3b29825da 100644 --- a/crates/oxc_ast/src/ast_builder_impl.rs +++ b/crates/oxc_ast/src/ast_builder_impl.rs @@ -9,7 +9,7 @@ use std::{borrow::Cow, mem}; use oxc_allocator::{Allocator, Box, FromIn, String, Vec}; -use oxc_span::{Atom, GetSpan, Span, SPAN}; +use oxc_span::{Atom, Span, SPAN}; use oxc_syntax::{number::NumberBase, operator::UnaryOperator, scope::ScopeId}; use crate::{ast::*, AstBuilder}; @@ -115,14 +115,14 @@ impl<'a> AstBuilder<'a> { /// Moves the expression out by replacing it with an [`Expression::NullLiteral`]. #[inline] pub fn move_expression(self, expr: &mut Expression<'a>) -> Expression<'a> { - let null_expr = self.expression_null_literal(expr.span()); + let null_expr = self.expression_null_literal(SPAN); mem::replace(expr, null_expr) } /// Moves the statement out by replacing it with a [`Statement::EmptyStatement`]. #[inline] pub fn move_statement(self, stmt: &mut Statement<'a>) -> Statement<'a> { - let empty_stmt = self.empty_statement(stmt.span()); + let empty_stmt = self.empty_statement(SPAN); mem::replace(stmt, Statement::EmptyStatement(self.alloc(empty_stmt))) }