Optimize functions calling.

This commit is contained in:
Stephen Chung
2022-09-27 23:04:22 +08:00
parent b141e8d0e1
commit fde8483f54
7 changed files with 64 additions and 72 deletions

View File

@@ -69,7 +69,7 @@ impl fmt::Debug for AST {
impl AST {
/// Create a new [`AST`].
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn new(
statements: impl IntoIterator<Item = Stmt>,
@@ -89,7 +89,7 @@ impl AST {
/// _(internals)_ Create a new [`AST`].
/// Exported under the `internals` feature only.
#[cfg(feature = "internals")]
#[inline(always)]
#[inline]
#[must_use]
pub fn new(
statements: impl IntoIterator<Item = Stmt>,
@@ -108,7 +108,7 @@ impl AST {
}
/// Create a new [`AST`] with a source name.
#[cfg(not(feature = "internals"))]
#[inline(always)]
#[inline]
#[must_use]
pub(crate) fn new_with_source(
statements: impl IntoIterator<Item = Stmt>,
@@ -126,7 +126,7 @@ impl AST {
/// _(internals)_ Create a new [`AST`] with a source name.
/// Exported under the `internals` feature only.
#[cfg(feature = "internals")]
#[inline(always)]
#[inline]
#[must_use]
pub fn new_with_source(
statements: impl IntoIterator<Item = Stmt>,
@@ -157,7 +157,7 @@ impl AST {
}
}
/// Get the source, if any.
#[inline(always)]
#[inline]
#[must_use]
pub fn source(&self) -> Option<&str> {
if self.source.is_empty() {
@@ -664,7 +664,6 @@ impl AST {
self.combine_filtered_impl(other, filter)
}
/// Combine one [`AST`] with another. The second [`AST`] is consumed.
#[inline]
fn combine_filtered_impl(
&mut self,
other: Self,
@@ -957,19 +956,21 @@ pub enum ASTNode<'a> {
}
impl<'a> From<&'a Stmt> for ASTNode<'a> {
#[inline(always)]
fn from(stmt: &'a Stmt) -> Self {
Self::Stmt(stmt)
}
}
impl<'a> From<&'a Expr> for ASTNode<'a> {
#[inline(always)]
fn from(expr: &'a Expr) -> Self {
Self::Expr(expr)
}
}
impl PartialEq for ASTNode<'_> {
#[inline(always)]
#[inline]
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Stmt(x), Self::Stmt(y)) => ptr::eq(*x, *y),
@@ -986,8 +987,8 @@ impl ASTNode<'_> {
#[must_use]
pub fn position(&self) -> Position {
match self {
ASTNode::Stmt(stmt) => stmt.position(),
ASTNode::Expr(expr) => expr.position(),
Self::Stmt(stmt) => stmt.position(),
Self::Expr(expr) => expr.position(),
}
}
}