Use interned strings for AST nodes.
This commit is contained in:
@@ -60,7 +60,7 @@ pub struct CustomExpr {
|
||||
/// List of keywords.
|
||||
pub inputs: StaticVec<Expr>,
|
||||
/// List of tokens actually parsed.
|
||||
pub tokens: StaticVec<Identifier>,
|
||||
pub tokens: StaticVec<ImmutableString>,
|
||||
/// Is the current [`Scope`][crate::Scope] possibly modified by this custom statement
|
||||
/// (e.g. introducing a new variable)?
|
||||
pub scope_may_be_changed: bool,
|
||||
@@ -183,7 +183,7 @@ pub struct FnCallExpr {
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
pub namespace: super::Namespace,
|
||||
/// Function name.
|
||||
pub name: Identifier,
|
||||
pub name: ImmutableString,
|
||||
/// Pre-calculated hashes.
|
||||
pub hashes: FnCallHashes,
|
||||
/// List of function call argument expressions.
|
||||
@@ -392,14 +392,18 @@ pub enum Expr {
|
||||
/// This is to avoid reading a pointer redirection during each variable access.
|
||||
Variable(
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
Box<(Option<NonZeroUsize>, super::Namespace, u64, Identifier)>,
|
||||
#[cfg(feature = "no_module")] Box<(Option<NonZeroUsize>, (), u64, Identifier)>,
|
||||
Box<(Option<NonZeroUsize>, super::Namespace, u64, ImmutableString)>,
|
||||
#[cfg(feature = "no_module")] Box<(Option<NonZeroUsize>, (), u64, ImmutableString)>,
|
||||
Option<NonZeroU8>,
|
||||
Position,
|
||||
),
|
||||
/// Property access - ((getter, hash), (setter, hash), prop)
|
||||
Property(
|
||||
Box<((Identifier, u64), (Identifier, u64), ImmutableString)>,
|
||||
Box<(
|
||||
(ImmutableString, u64),
|
||||
(ImmutableString, u64),
|
||||
ImmutableString,
|
||||
)>,
|
||||
Position,
|
||||
),
|
||||
/// xxx `.` method `(` expr `,` ... `)`
|
||||
|
@@ -1,6 +1,6 @@
|
||||
//! Module defining script identifiers.
|
||||
|
||||
use crate::{Identifier, Position};
|
||||
use crate::{ImmutableString, Position};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
use std::{
|
||||
@@ -14,7 +14,7 @@ use std::{
|
||||
#[derive(Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Ident {
|
||||
/// Identifier name.
|
||||
pub name: Identifier,
|
||||
pub name: ImmutableString,
|
||||
/// Position.
|
||||
pub pos: Position,
|
||||
}
|
||||
@@ -34,7 +34,7 @@ impl AsRef<str> for Ident {
|
||||
}
|
||||
|
||||
impl Deref for Ident {
|
||||
type Target = Identifier;
|
||||
type Target = ImmutableString;
|
||||
|
||||
#[inline(always)]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
@@ -50,12 +50,6 @@ impl DerefMut for Ident {
|
||||
}
|
||||
|
||||
impl Ident {
|
||||
/// An empty [`Ident`].
|
||||
pub const EMPTY: Self = Self {
|
||||
name: Identifier::new_const(),
|
||||
pos: Position::NONE,
|
||||
};
|
||||
|
||||
/// Get the name of the identifier as a string slice.
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#![cfg(not(feature = "no_function"))]
|
||||
|
||||
use super::{FnAccess, StmtBlock};
|
||||
use crate::{Identifier, SmartString, StaticVec};
|
||||
use crate::{Identifier, ImmutableString, StaticVec};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
use std::{fmt, hash::Hash};
|
||||
@@ -38,11 +38,11 @@ pub struct ScriptFnDef {
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub environ: Option<EncapsulatedEnviron>,
|
||||
/// Function name.
|
||||
pub name: Identifier,
|
||||
pub name: ImmutableString,
|
||||
/// Function access mode.
|
||||
pub access: FnAccess,
|
||||
/// Names of function parameters.
|
||||
pub params: StaticVec<Identifier>,
|
||||
pub params: StaticVec<ImmutableString>,
|
||||
/// _(metadata)_ Function doc-comments (if any).
|
||||
/// Exported under the `metadata` feature only.
|
||||
///
|
||||
@@ -71,7 +71,7 @@ impl fmt::Display for ScriptFnDef {
|
||||
self.name,
|
||||
self.params
|
||||
.iter()
|
||||
.map(SmartString::as_str)
|
||||
.map(|s| s.as_str())
|
||||
.collect::<StaticVec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
@@ -132,7 +132,7 @@ impl<'a> From<&'a ScriptFnDef> for ScriptFnMetadata<'a> {
|
||||
fn from(value: &'a ScriptFnDef) -> Self {
|
||||
Self {
|
||||
name: &value.name,
|
||||
params: value.params.iter().map(SmartString::as_str).collect(),
|
||||
params: value.params.iter().map(|s| s.as_str()).collect(),
|
||||
access: value.access,
|
||||
#[cfg(feature = "metadata")]
|
||||
comments: value.comments.iter().map(<_>::as_ref).collect(),
|
||||
|
@@ -594,7 +594,7 @@ pub enum Stmt {
|
||||
/// This variant does not map to any language structure. It is currently only used only to
|
||||
/// convert a normal variable into a shared variable when the variable is _captured_ by a closure.
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Share(Box<crate::Identifier>, Position),
|
||||
Share(crate::ImmutableString, Position),
|
||||
}
|
||||
|
||||
impl Default for Stmt {
|
||||
|
Reference in New Issue
Block a user