Inline all the things

This commit is contained in:
Lukas Wirth 2024-07-07 11:18:40 +02:00
parent c08d419fba
commit 35aa238020
2 changed files with 1032 additions and 0 deletions

File diff suppressed because it is too large Load diff

View file

@ -122,18 +122,21 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
if field.is_many() { if field.is_many() {
quote! { quote! {
#[inline]
pub fn #method_name(&self) -> AstChildren<#ty> { pub fn #method_name(&self) -> AstChildren<#ty> {
support::children(&self.syntax) support::children(&self.syntax)
} }
} }
} else if let Some(token_kind) = field.token_kind() { } else if let Some(token_kind) = field.token_kind() {
quote! { quote! {
#[inline]
pub fn #method_name(&self) -> Option<#ty> { pub fn #method_name(&self) -> Option<#ty> {
support::token(&self.syntax, #token_kind) support::token(&self.syntax, #token_kind)
} }
} }
} else { } else {
quote! { quote! {
#[inline]
pub fn #method_name(&self) -> Option<#ty> { pub fn #method_name(&self) -> Option<#ty> {
support::child(&self.syntax) support::child(&self.syntax)
} }
@ -156,12 +159,15 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
}, },
quote! { quote! {
impl AstNode for #name { impl AstNode for #name {
#[inline]
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
kind == #kind kind == #kind
} }
#[inline]
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None } if Self::can_cast(syntax.kind()) { Some(Self { syntax }) } else { None }
} }
#[inline]
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
}, },
@ -190,9 +196,11 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
} else { } else {
quote! { quote! {
impl AstNode for #name { impl AstNode for #name {
#[inline]
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
matches!(kind, #(#kinds)|*) matches!(kind, #(#kinds)|*)
} }
#[inline]
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() { let res = match syntax.kind() {
#( #(
@ -202,6 +210,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
}; };
Some(res) Some(res)
} }
#[inline]
fn syntax(&self) -> &SyntaxNode { fn syntax(&self) -> &SyntaxNode {
match self { match self {
#( #(
@ -226,6 +235,7 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
quote! { quote! {
#( #(
impl From<#variants> for #name { impl From<#variants> for #name {
#[inline]
fn from(node: #variants) -> #name { fn from(node: #variants) -> #name {
#name::#variants(node) #name::#variants(node)
} }
@ -270,12 +280,15 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> String {
} }
} }
impl AstNode for #name { impl AstNode for #name {
#[inline]
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
matches!(kind, #(#kinds)|*) matches!(kind, #(#kinds)|*)
} }
#[inline]
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
Self::can_cast(syntax.kind()).then_some(#name { syntax }) Self::can_cast(syntax.kind()).then_some(#name { syntax })
} }
#[inline]
fn syntax(&self) -> &SyntaxNode { fn syntax(&self) -> &SyntaxNode {
&self.syntax &self.syntax
} }