diff --git a/boa_engine/src/lib.rs b/boa_engine/src/lib.rs index 65cd6ff6c19..4b9f6702b20 100644 --- a/boa_engine/src/lib.rs +++ b/boa_engine/src/lib.rs @@ -35,7 +35,6 @@ clippy::needless_pass_by_value, clippy::match_wildcard_for_single_variants, clippy::map_unwrap_or, - clippy::missing_inline_in_public_items, unused_qualifications, unused_import_braces, unused_lifetimes, @@ -53,6 +52,7 @@ nonstandard_style, )] #![allow( + clippy::missing_inline_in_public_items, clippy::module_name_repetitions, clippy::cast_possible_truncation, clippy::cast_sign_loss, diff --git a/boa_engine/src/syntax/ast/expression/access.rs b/boa_engine/src/syntax/ast/expression/access.rs index ce6fdec6e43..9ce723a450d 100644 --- a/boa_engine/src/syntax/ast/expression/access.rs +++ b/boa_engine/src/syntax/ast/expression/access.rs @@ -25,12 +25,14 @@ impl PropertyAccessField { } impl From for PropertyAccessField { + #[inline] fn from(id: Sym) -> Self { Self::Const(id) } } impl From for PropertyAccessField { + #[inline] fn from(expr: Expression) -> Self { Self::Expr(Box::new(expr)) } @@ -66,15 +68,18 @@ pub struct PropertyAccess { } impl PropertyAccess { + #[inline] pub fn target(&self) -> &Expression { &self.target } + #[inline] pub fn field(&self) -> &PropertyAccessField { &self.field } /// Creates a `PropertyAccess` AST Expression. + #[inline] pub fn new(target: Expression, field: F) -> Self where F: Into, @@ -97,6 +102,7 @@ impl PropertyAccess { } impl ToInternedString for PropertyAccess { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let target = self.target.to_interned_string(interner); match self.field { @@ -109,6 +115,7 @@ impl ToInternedString for PropertyAccess { } impl From for Expression { + #[inline] fn from(access: PropertyAccess) -> Self { Self::PropertyAccess(access) } @@ -166,6 +173,7 @@ impl PrivatePropertyAccess { } impl ToInternedString for PrivatePropertyAccess { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!( "{}.#{}", @@ -176,6 +184,7 @@ impl ToInternedString for PrivatePropertyAccess { } impl From for Expression { + #[inline] fn from(access: PrivatePropertyAccess) -> Self { Self::PrivatePropertyAccess(access) } @@ -201,6 +210,7 @@ impl SuperPropertyAccess { } /// Gets the name of the field to retrieve. + #[inline] pub fn field(&self) -> &PropertyAccessField { &self.field } @@ -217,6 +227,7 @@ impl SuperPropertyAccess { } impl ToInternedString for SuperPropertyAccess { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { match &self.field { PropertyAccessField::Const(field) => { @@ -230,6 +241,7 @@ impl ToInternedString for SuperPropertyAccess { } impl From for Expression { + #[inline] fn from(access: SuperPropertyAccess) -> Self { Self::SuperPropertyAccess(access) } diff --git a/boa_engine/src/syntax/ast/expression/await.rs b/boa_engine/src/syntax/ast/expression/await.rs index d49132c948a..e6964ff8119 100644 --- a/boa_engine/src/syntax/ast/expression/await.rs +++ b/boa_engine/src/syntax/ast/expression/await.rs @@ -42,18 +42,21 @@ impl From for Await where T: Into>, { + #[inline] fn from(e: T) -> Self { Self { expr: e.into() } } } impl ToInternedString for Await { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!("await {}", self.expr.to_indented_string(interner, 0)) } } impl From for Expression { + #[inline] fn from(awaitexpr: Await) -> Self { Self::Await(awaitexpr) } diff --git a/boa_engine/src/syntax/ast/expression/call.rs b/boa_engine/src/syntax/ast/expression/call.rs index 77d6efee35e..51d3ecf0b9c 100644 --- a/boa_engine/src/syntax/ast/expression/call.rs +++ b/boa_engine/src/syntax/ast/expression/call.rs @@ -58,6 +58,7 @@ impl Call { } impl ToInternedString for Call { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!( "{}({})", @@ -68,6 +69,7 @@ impl ToInternedString for Call { } impl From for Expression { + #[inline] fn from(call: Call) -> Self { Self::Call(call) } @@ -113,12 +115,14 @@ impl SuperCall { } impl ToInternedString for SuperCall { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!("super({})", join_nodes(interner, &self.args)) } } impl From for Expression { + #[inline] fn from(call: SuperCall) -> Self { Self::SuperCall(call) } diff --git a/boa_engine/src/syntax/ast/expression/identifier.rs b/boa_engine/src/syntax/ast/expression/identifier.rs index 2278b210820..3143901a6d9 100644 --- a/boa_engine/src/syntax/ast/expression/identifier.rs +++ b/boa_engine/src/syntax/ast/expression/identifier.rs @@ -30,12 +30,14 @@ pub struct Identifier { } impl PartialEq for Identifier { + #[inline] fn eq(&self, other: &Sym) -> bool { self.ident == *other } } impl PartialEq for Sym { + #[inline] fn eq(&self, other: &Identifier) -> bool { *self == other.ident } @@ -43,11 +45,13 @@ impl PartialEq for Sym { impl Identifier { /// Creates a new identifier AST Expression. + #[inline] pub fn new(ident: Sym) -> Self { Self { ident } } /// Retrieves the identifier's string symbol in the interner. + #[inline] pub fn sym(self) -> Sym { self.ident } @@ -72,18 +76,21 @@ impl Identifier { } impl ToInternedString for Identifier { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { interner.resolve_expect(self.ident).to_owned() } } impl From for Identifier { + #[inline] fn from(sym: Sym) -> Self { Self { ident: sym } } } impl From for Expression { + #[inline] fn from(local: Identifier) -> Self { Self::Identifier(local) } diff --git a/boa_engine/src/syntax/ast/expression/literal/array.rs b/boa_engine/src/syntax/ast/expression/literal/array.rs index 8516359521b..76c3977f3db 100644 --- a/boa_engine/src/syntax/ast/expression/literal/array.rs +++ b/boa_engine/src/syntax/ast/expression/literal/array.rs @@ -59,6 +59,7 @@ impl ArrayLiteral { } impl AsRef<[Option]> for ArrayLiteral { + #[inline] fn as_ref(&self) -> &[Option] { &self.arr } @@ -68,6 +69,7 @@ impl From for ArrayLiteral where T: Into]>>, { + #[inline] fn from(decl: T) -> Self { Self { arr: decl.into(), @@ -77,6 +79,7 @@ where } impl ToInternedString for ArrayLiteral { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let mut buf = String::from("["); let mut first = true; @@ -96,6 +99,7 @@ impl ToInternedString for ArrayLiteral { } impl From for Expression { + #[inline] fn from(arr: ArrayLiteral) -> Self { Self::ArrayLiteral(arr) } diff --git a/boa_engine/src/syntax/ast/expression/literal/mod.rs b/boa_engine/src/syntax/ast/expression/literal/mod.rs index 3a5c8125b3c..a809b369e82 100644 --- a/boa_engine/src/syntax/ast/expression/literal/mod.rs +++ b/boa_engine/src/syntax/ast/expression/literal/mod.rs @@ -120,48 +120,56 @@ pub enum Literal { } impl From for Literal { + #[inline] fn from(string: Sym) -> Self { Self::String(string) } } impl From for Literal { + #[inline] fn from(num: f64) -> Self { Self::Num(num) } } impl From for Literal { + #[inline] fn from(i: i32) -> Self { Self::Int(i) } } impl From for Literal { + #[inline] fn from(i: BigInt) -> Self { Self::BigInt(Box::new(i)) } } impl From> for Literal { + #[inline] fn from(i: Box) -> Self { Self::BigInt(i) } } impl From for Literal { + #[inline] fn from(b: bool) -> Self { Self::Bool(b) } } impl From for Expression { + #[inline] fn from(lit: Literal) -> Self { Expression::Literal(lit) } } impl ToInternedString for Literal { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { match *self { Self::String(st) => { diff --git a/boa_engine/src/syntax/ast/expression/literal/object/mod.rs b/boa_engine/src/syntax/ast/expression/literal/object/mod.rs index da9690c9f18..020d5a466b9 100644 --- a/boa_engine/src/syntax/ast/expression/literal/object/mod.rs +++ b/boa_engine/src/syntax/ast/expression/literal/object/mod.rs @@ -39,6 +39,7 @@ pub struct ObjectLiteral { } impl ObjectLiteral { + #[inline] pub fn properties(&self) -> &[PropertyDefinition] { &self.properties } @@ -133,6 +134,7 @@ impl ObjectLiteral { } impl ToInternedString for ObjectLiteral { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { self.to_indented_string(interner, 0) } @@ -142,6 +144,7 @@ impl From for ObjectLiteral where T: Into>, { + #[inline] fn from(props: T) -> Self { Self { properties: props.into(), @@ -150,6 +153,7 @@ where } impl From for Expression { + #[inline] fn from(obj: ObjectLiteral) -> Self { Self::ObjectLiteral(obj) } diff --git a/boa_engine/src/syntax/ast/expression/literal/template.rs b/boa_engine/src/syntax/ast/expression/literal/template.rs index d6f37cbc0a6..1a3b55bec2e 100644 --- a/boa_engine/src/syntax/ast/expression/literal/template.rs +++ b/boa_engine/src/syntax/ast/expression/literal/template.rs @@ -19,6 +19,7 @@ pub struct TemplateLiteral { } impl From for Expression { + #[inline] fn from(tem: TemplateLiteral) -> Self { Self::TemplateLiteral(tem) } @@ -32,6 +33,7 @@ pub enum TemplateElement { } impl TemplateLiteral { + #[inline] pub fn new(elements: Box<[TemplateElement]>) -> Self { Self { elements } } @@ -58,6 +60,7 @@ impl TemplateLiteral { } impl ToInternedString for TemplateLiteral { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let mut buf = "`".to_owned(); diff --git a/boa_engine/src/syntax/ast/expression/mod.rs b/boa_engine/src/syntax/ast/expression/mod.rs index 817948792ef..c9584ab41d4 100644 --- a/boa_engine/src/syntax/ast/expression/mod.rs +++ b/boa_engine/src/syntax/ast/expression/mod.rs @@ -143,6 +143,7 @@ pub enum Expression { impl Expression { /// Creates a string of the value of the expression with the given indentation. + #[inline] pub fn to_indented_string(&self, interner: &Interner, indentation: usize) -> String { self.to_no_indent_string(interner, indentation) } @@ -274,12 +275,14 @@ impl Expression { } impl From for Statement { + #[inline] fn from(expr: Expression) -> Self { Statement::Expression(expr) } } impl ToInternedString for Expression { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { self.to_indented_string(interner, 0) } diff --git a/boa_engine/src/syntax/ast/expression/new.rs b/boa_engine/src/syntax/ast/expression/new.rs index 849faf2654f..7f7a88c6a0b 100644 --- a/boa_engine/src/syntax/ast/expression/new.rs +++ b/boa_engine/src/syntax/ast/expression/new.rs @@ -26,11 +26,13 @@ pub struct New { impl New { /// Gets the name of the function call. + #[inline] pub fn expr(&self) -> &Expression { self.call.expr() } /// Retrieves the arguments passed to the function. + #[inline] pub fn args(&self) -> &[Expression] { self.call.args() } @@ -52,18 +54,21 @@ impl New { } impl From for New { + #[inline] fn from(call: Call) -> Self { Self { call } } } impl ToInternedString for New { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!("new {}", self.call.to_interned_string(interner)) } } impl From for Expression { + #[inline] fn from(new: New) -> Self { Self::New(new) } diff --git a/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs b/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs index 3547f6e67cb..7a12785654c 100644 --- a/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs +++ b/boa_engine/src/syntax/ast/expression/operator/assign/mod.rs @@ -49,16 +49,19 @@ impl Assign { } /// Gets the operator of the assignment operation. + #[inline] pub fn op(&self) -> op::AssignOp { self.op } /// Gets the left hand side of the assignment operation. + #[inline] pub fn lhs(&self) -> &AssignTarget { &self.lhs } /// Gets the right hand side of the assignment operation. + #[inline] pub fn rhs(&self) -> &Expression { &self.rhs } @@ -87,6 +90,7 @@ impl Assign { } impl ToInternedString for Assign { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!( "{} {} {}", @@ -98,6 +102,7 @@ impl ToInternedString for Assign { } impl From for Expression { + #[inline] fn from(op: Assign) -> Self { Self::Assign(op) } @@ -148,6 +153,7 @@ impl AssignTarget { } impl ToInternedString for AssignTarget { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { match self { AssignTarget::Identifier(id) => id.to_interned_string(interner), @@ -160,6 +166,7 @@ impl ToInternedString for AssignTarget { } impl From for AssignTarget { + #[inline] fn from(target: Identifier) -> Self { Self::Identifier(target) } diff --git a/boa_engine/src/syntax/ast/expression/operator/assign/op.rs b/boa_engine/src/syntax/ast/expression/operator/assign/op.rs index 45f1d0e1b03..5900b2745d2 100644 --- a/boa_engine/src/syntax/ast/expression/operator/assign/op.rs +++ b/boa_engine/src/syntax/ast/expression/operator/assign/op.rs @@ -236,6 +236,7 @@ impl AssignOp { } impl std::fmt::Display for AssignOp { + #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.as_str()) } diff --git a/boa_engine/src/syntax/ast/expression/operator/binary/mod.rs b/boa_engine/src/syntax/ast/expression/operator/binary/mod.rs index b045a80a28b..b90689c99a8 100644 --- a/boa_engine/src/syntax/ast/expression/operator/binary/mod.rs +++ b/boa_engine/src/syntax/ast/expression/operator/binary/mod.rs @@ -29,16 +29,19 @@ impl Binary { } /// Gets the binary operation of the Expression. + #[inline] pub fn op(&self) -> op::BinaryOp { self.op } /// Gets the left hand side of the binary operation. + #[inline] pub fn lhs(&self) -> &Expression { &self.lhs } /// Gets the right hand side of the binary operation. + #[inline] pub fn rhs(&self) -> &Expression { &self.rhs } @@ -55,6 +58,7 @@ impl Binary { } impl ToInternedString for Binary { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!( "{} {} {}", @@ -66,6 +70,7 @@ impl ToInternedString for Binary { } impl From for Expression { + #[inline] fn from(op: Binary) -> Self { Self::Binary(op) } diff --git a/boa_engine/src/syntax/ast/expression/operator/binary/op.rs b/boa_engine/src/syntax/ast/expression/operator/binary/op.rs index f4cc00b2c59..cb6739b5f3d 100644 --- a/boa_engine/src/syntax/ast/expression/operator/binary/op.rs +++ b/boa_engine/src/syntax/ast/expression/operator/binary/op.rs @@ -31,24 +31,28 @@ pub enum BinaryOp { } impl From for BinaryOp { + #[inline] fn from(op: ArithmeticOp) -> Self { Self::Arithmetic(op) } } impl From for BinaryOp { + #[inline] fn from(op: BitwiseOp) -> Self { Self::Bitwise(op) } } impl From for BinaryOp { + #[inline] fn from(op: RelationalOp) -> Self { Self::Relational(op) } } impl From for BinaryOp { + #[inline] fn from(op: LogicalOp) -> Self { Self::Logical(op) } @@ -68,6 +72,7 @@ impl BinaryOp { } impl Display for BinaryOp { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{}", self.as_str()) } @@ -177,6 +182,7 @@ impl ArithmeticOp { } impl Display for ArithmeticOp { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{}", self.as_str()) } @@ -291,6 +297,7 @@ impl BitwiseOp { } impl Display for BitwiseOp { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{}", self.as_str()) } @@ -487,6 +494,7 @@ impl RelationalOp { } impl Display for RelationalOp { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{}", self.as_str()) } @@ -558,6 +566,7 @@ impl LogicalOp { } impl Display for LogicalOp { + #[inline] fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{}", self.as_str()) } diff --git a/boa_engine/src/syntax/ast/expression/operator/conditional.rs b/boa_engine/src/syntax/ast/expression/operator/conditional.rs index 886466ff37b..b32d9291e73 100644 --- a/boa_engine/src/syntax/ast/expression/operator/conditional.rs +++ b/boa_engine/src/syntax/ast/expression/operator/conditional.rs @@ -24,19 +24,23 @@ pub struct Conditional { } impl Conditional { + #[inline] pub fn cond(&self) -> &Expression { &self.condition } + #[inline] pub fn if_true(&self) -> &Expression { &self.if_true } + #[inline] pub fn if_false(&self) -> &Expression { &self.if_false } /// Creates a `ConditionalOp` AST Expression. + #[inline] pub fn new(condition: Expression, if_true: Expression, if_false: Expression) -> Self { Self { condition: Box::new(condition), @@ -61,6 +65,7 @@ impl Conditional { } impl ToInternedString for Conditional { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!( "{} ? {} : {}", @@ -72,6 +77,7 @@ impl ToInternedString for Conditional { } impl From for Expression { + #[inline] fn from(cond_op: Conditional) -> Self { Self::Conditional(cond_op) } diff --git a/boa_engine/src/syntax/ast/expression/operator/unary/mod.rs b/boa_engine/src/syntax/ast/expression/operator/unary/mod.rs index 216ac51fee7..0f43bc2b7c8 100644 --- a/boa_engine/src/syntax/ast/expression/operator/unary/mod.rs +++ b/boa_engine/src/syntax/ast/expression/operator/unary/mod.rs @@ -29,11 +29,13 @@ impl Unary { } /// Gets the unary operation of the Expression. + #[inline] pub fn op(&self) -> op::UnaryOp { self.op } /// Gets the target of this unary operator. + #[inline] pub fn target(&self) -> &Expression { self.target.as_ref() } @@ -50,6 +52,7 @@ impl Unary { } impl ToInternedString for Unary { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let space = match self.op { op::UnaryOp::TypeOf | op::UnaryOp::Delete | op::UnaryOp::Void => " ", @@ -64,6 +67,7 @@ impl ToInternedString for Unary { } impl From for Expression { + #[inline] fn from(op: Unary) -> Self { Self::Unary(op) } diff --git a/boa_engine/src/syntax/ast/expression/operator/unary/op.rs b/boa_engine/src/syntax/ast/expression/operator/unary/op.rs index 76c53d26ca6..a14a634d550 100644 --- a/boa_engine/src/syntax/ast/expression/operator/unary/op.rs +++ b/boa_engine/src/syntax/ast/expression/operator/unary/op.rs @@ -208,6 +208,7 @@ impl UnaryOp { } impl std::fmt::Display for UnaryOp { + #[inline] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.as_str()) } diff --git a/boa_engine/src/syntax/ast/expression/spread.rs b/boa_engine/src/syntax/ast/expression/spread.rs index 13ce9d83776..63082288759 100644 --- a/boa_engine/src/syntax/ast/expression/spread.rs +++ b/boa_engine/src/syntax/ast/expression/spread.rs @@ -28,11 +28,13 @@ pub struct Spread { } impl Spread { + #[inline] pub fn val(&self) -> &Expression { &self.val } /// Creates a `Spread` AST Expression. + #[inline] pub fn new(val: Expression) -> Self { Self { val: Box::new(val) } } @@ -49,12 +51,14 @@ impl Spread { } impl ToInternedString for Spread { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { format!("...{}", self.val().to_interned_string(interner)) } } impl From for Expression { + #[inline] fn from(spread: Spread) -> Self { Self::Spread(spread) } diff --git a/boa_engine/src/syntax/ast/expression/tagged_template.rs b/boa_engine/src/syntax/ast/expression/tagged_template.rs index 887dc845dea..7f83218dfdc 100644 --- a/boa_engine/src/syntax/ast/expression/tagged_template.rs +++ b/boa_engine/src/syntax/ast/expression/tagged_template.rs @@ -16,6 +16,7 @@ pub struct TaggedTemplate { impl TaggedTemplate { /// Creates a new tagged template with a tag, the list of raw strings, the cooked strings and /// the expressions. + #[inline] pub fn new( tag: Expression, raws: Box<[Sym]>, @@ -30,22 +31,27 @@ impl TaggedTemplate { } } + #[inline] pub(crate) fn tag(&self) -> &Expression { &self.tag } + #[inline] pub(crate) fn raws(&self) -> &[Sym] { &self.raws } + #[inline] pub(crate) fn cookeds(&self) -> &[Option] { &self.cookeds } + #[inline] pub(crate) fn exprs(&self) -> &[Expression] { &self.exprs } + #[inline] pub(crate) fn contains_arguments(&self) -> bool { self.tag.contains_arguments() || self.exprs.iter().any(Expression::contains_arguments) } @@ -57,6 +63,7 @@ impl TaggedTemplate { } impl ToInternedString for TaggedTemplate { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let mut buf = format!("{}`", self.tag.to_interned_string(interner)); for (&raw, expr) in self.raws.iter().zip(self.exprs.iter()) { @@ -73,6 +80,7 @@ impl ToInternedString for TaggedTemplate { } impl From for Expression { + #[inline] fn from(template: TaggedTemplate) -> Self { Self::TaggedTemplate(template) } diff --git a/boa_engine/src/syntax/ast/expression/yield.rs b/boa_engine/src/syntax/ast/expression/yield.rs index 2f028cb7ee8..79c1e255ba2 100644 --- a/boa_engine/src/syntax/ast/expression/yield.rs +++ b/boa_engine/src/syntax/ast/expression/yield.rs @@ -20,15 +20,18 @@ pub struct Yield { } impl Yield { + #[inline] pub fn expr(&self) -> Option<&Expression> { self.expr.as_ref().map(Box::as_ref) } + #[inline] pub fn delegate(&self) -> bool { self.delegate } /// Creates a `Yield` AST Expression. + #[inline] pub fn new(expr: Option, delegate: bool) -> Self { Self { expr: expr.map(Box::new), @@ -48,12 +51,14 @@ impl Yield { } impl From for Expression { + #[inline] fn from(r#yield: Yield) -> Self { Self::Yield(r#yield) } } impl ToInternedString for Yield { + #[inline] fn to_interned_string(&self, interner: &Interner) -> String { let y = if self.delegate { "yield*" } else { "yield" }; if let Some(ex) = self.expr() {