mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(ast)!: educe byte size of TaggedTemplateExpression::quasi by Boxing it (#5679)
This commit is contained in:
parent
7415e85764
commit
afc4548ef4
5 changed files with 27 additions and 24 deletions
|
|
@ -461,7 +461,7 @@ pub struct TaggedTemplateExpression<'a> {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub tag: Expression<'a>,
|
pub tag: Expression<'a>,
|
||||||
pub quasi: TemplateLiteral<'a>,
|
pub quasi: Box<'a, TemplateLiteral<'a>>,
|
||||||
pub type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
|
pub type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -138,12 +138,12 @@ const _: () = {
|
||||||
assert!(offset_of!(TemplateLiteral, quasis) == 8usize);
|
assert!(offset_of!(TemplateLiteral, quasis) == 8usize);
|
||||||
assert!(offset_of!(TemplateLiteral, expressions) == 40usize);
|
assert!(offset_of!(TemplateLiteral, expressions) == 40usize);
|
||||||
|
|
||||||
assert!(size_of::<TaggedTemplateExpression>() == 104usize);
|
assert!(size_of::<TaggedTemplateExpression>() == 40usize);
|
||||||
assert!(align_of::<TaggedTemplateExpression>() == 8usize);
|
assert!(align_of::<TaggedTemplateExpression>() == 8usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, span) == 0usize);
|
assert!(offset_of!(TaggedTemplateExpression, span) == 0usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize);
|
assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, quasi) == 24usize);
|
assert!(offset_of!(TaggedTemplateExpression, quasi) == 24usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 96usize);
|
assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 32usize);
|
||||||
|
|
||||||
assert!(size_of::<TemplateElement>() == 48usize);
|
assert!(size_of::<TemplateElement>() == 48usize);
|
||||||
assert!(align_of::<TemplateElement>() == 8usize);
|
assert!(align_of::<TemplateElement>() == 8usize);
|
||||||
|
|
@ -1693,12 +1693,12 @@ const _: () = {
|
||||||
assert!(offset_of!(TemplateLiteral, quasis) == 8usize);
|
assert!(offset_of!(TemplateLiteral, quasis) == 8usize);
|
||||||
assert!(offset_of!(TemplateLiteral, expressions) == 24usize);
|
assert!(offset_of!(TemplateLiteral, expressions) == 24usize);
|
||||||
|
|
||||||
assert!(size_of::<TaggedTemplateExpression>() == 60usize);
|
assert!(size_of::<TaggedTemplateExpression>() == 24usize);
|
||||||
assert!(align_of::<TaggedTemplateExpression>() == 4usize);
|
assert!(align_of::<TaggedTemplateExpression>() == 4usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, span) == 0usize);
|
assert!(offset_of!(TaggedTemplateExpression, span) == 0usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize);
|
assert!(offset_of!(TaggedTemplateExpression, tag) == 8usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, quasi) == 16usize);
|
assert!(offset_of!(TaggedTemplateExpression, quasi) == 16usize);
|
||||||
assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 56usize);
|
assert!(offset_of!(TaggedTemplateExpression, type_parameters) == 20usize);
|
||||||
|
|
||||||
assert!(size_of::<TemplateElement>() == 28usize);
|
assert!(size_of::<TemplateElement>() == 28usize);
|
||||||
assert!(align_of::<TemplateElement>() == 4usize);
|
assert!(align_of::<TemplateElement>() == 4usize);
|
||||||
|
|
|
||||||
|
|
@ -1075,15 +1075,16 @@ impl<'a> AstBuilder<'a> {
|
||||||
/// - quasi
|
/// - quasi
|
||||||
/// - type_parameters
|
/// - type_parameters
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn expression_tagged_template<T1>(
|
pub fn expression_tagged_template<T1, T2>(
|
||||||
self,
|
self,
|
||||||
span: Span,
|
span: Span,
|
||||||
tag: Expression<'a>,
|
tag: Expression<'a>,
|
||||||
quasi: TemplateLiteral<'a>,
|
quasi: T1,
|
||||||
type_parameters: T1,
|
type_parameters: T2,
|
||||||
) -> Expression<'a>
|
) -> Expression<'a>
|
||||||
where
|
where
|
||||||
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>,
|
||||||
|
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
||||||
{
|
{
|
||||||
Expression::TaggedTemplateExpression(self.alloc(self.tagged_template_expression(
|
Expression::TaggedTemplateExpression(self.alloc(self.tagged_template_expression(
|
||||||
span,
|
span,
|
||||||
|
|
@ -1989,20 +1990,21 @@ impl<'a> AstBuilder<'a> {
|
||||||
/// - quasi
|
/// - quasi
|
||||||
/// - type_parameters
|
/// - type_parameters
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn tagged_template_expression<T1>(
|
pub fn tagged_template_expression<T1, T2>(
|
||||||
self,
|
self,
|
||||||
span: Span,
|
span: Span,
|
||||||
tag: Expression<'a>,
|
tag: Expression<'a>,
|
||||||
quasi: TemplateLiteral<'a>,
|
quasi: T1,
|
||||||
type_parameters: T1,
|
type_parameters: T2,
|
||||||
) -> TaggedTemplateExpression<'a>
|
) -> TaggedTemplateExpression<'a>
|
||||||
where
|
where
|
||||||
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>,
|
||||||
|
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
||||||
{
|
{
|
||||||
TaggedTemplateExpression {
|
TaggedTemplateExpression {
|
||||||
span,
|
span,
|
||||||
tag,
|
tag,
|
||||||
quasi,
|
quasi: quasi.into_in(self.allocator),
|
||||||
type_parameters: type_parameters.into_in(self.allocator),
|
type_parameters: type_parameters.into_in(self.allocator),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2017,15 +2019,16 @@ impl<'a> AstBuilder<'a> {
|
||||||
/// - quasi
|
/// - quasi
|
||||||
/// - type_parameters
|
/// - type_parameters
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn alloc_tagged_template_expression<T1>(
|
pub fn alloc_tagged_template_expression<T1, T2>(
|
||||||
self,
|
self,
|
||||||
span: Span,
|
span: Span,
|
||||||
tag: Expression<'a>,
|
tag: Expression<'a>,
|
||||||
quasi: TemplateLiteral<'a>,
|
quasi: T1,
|
||||||
type_parameters: T1,
|
type_parameters: T2,
|
||||||
) -> Box<'a, TaggedTemplateExpression<'a>>
|
) -> Box<'a, TaggedTemplateExpression<'a>>
|
||||||
where
|
where
|
||||||
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
T1: IntoIn<'a, Box<'a, TemplateLiteral<'a>>>,
|
||||||
|
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
|
||||||
{
|
{
|
||||||
Box::new_in(
|
Box::new_in(
|
||||||
self.tagged_template_expression(span, tag, quasi, type_parameters),
|
self.tagged_template_expression(span, tag, quasi, type_parameters),
|
||||||
|
|
|
||||||
|
|
@ -2612,10 +2612,10 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTag<'a, 't> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
|
pub fn quasi(self) -> &'t Box<'a, TemplateLiteral<'a>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
||||||
as *const TemplateLiteral<'a>)
|
as *const Box<'a, TemplateLiteral<'a>>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2684,10 +2684,10 @@ impl<'a, 't> TaggedTemplateExpressionWithoutTypeParameters<'a, 't> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn quasi(self) -> &'t TemplateLiteral<'a> {
|
pub fn quasi(self) -> &'t Box<'a, TemplateLiteral<'a>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
&*((self.0 as *const u8).add(OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
||||||
as *const TemplateLiteral<'a>)
|
as *const Box<'a, TemplateLiteral<'a>>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -486,8 +486,8 @@ pub(crate) unsafe fn walk_tagged_template_expression<'a, Tr: Traverse<'a>>(
|
||||||
ctx.retag_stack(AncestorType::TaggedTemplateExpressionQuasi);
|
ctx.retag_stack(AncestorType::TaggedTemplateExpressionQuasi);
|
||||||
walk_template_literal(
|
walk_template_literal(
|
||||||
traverser,
|
traverser,
|
||||||
(node as *mut u8).add(ancestor::OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
(&mut **((node as *mut u8).add(ancestor::OFFSET_TAGGED_TEMPLATE_EXPRESSION_QUASI)
|
||||||
as *mut TemplateLiteral,
|
as *mut Box<TemplateLiteral>)) as *mut _,
|
||||||
ctx,
|
ctx,
|
||||||
);
|
);
|
||||||
if let Some(field) = &mut *((node as *mut u8)
|
if let Some(field) = &mut *((node as *mut u8)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue