Store short index in variable access.
This commit is contained in:
23
src/ast.rs
23
src/ast.rs
@@ -9,7 +9,7 @@ use crate::stdlib::{
|
||||
fmt,
|
||||
hash::Hash,
|
||||
iter::empty,
|
||||
num::NonZeroUsize,
|
||||
num::{NonZeroU8, NonZeroUsize},
|
||||
ops::{Add, AddAssign},
|
||||
string::String,
|
||||
vec,
|
||||
@@ -1574,8 +1574,15 @@ pub enum Expr {
|
||||
),
|
||||
/// ()
|
||||
Unit(Position),
|
||||
/// Variable access - (optional index, optional (hash, modules), variable name)
|
||||
Variable(Box<(Option<NonZeroUsize>, Option<(u64, NamespaceRef)>, Ident)>),
|
||||
/// Variable access - optional short index, (optional index, optional (hash, modules), variable name)
|
||||
///
|
||||
/// The short index is [`u8`] which is used when the index is <= 255, which should be the vast
|
||||
/// majority of cases (unless there are more than 255 variables defined!).
|
||||
/// This is to avoid reading a pointer redirection during each variable access.
|
||||
Variable(
|
||||
Option<NonZeroU8>,
|
||||
Box<(Option<NonZeroUsize>, Option<(u64, NamespaceRef)>, Ident)>,
|
||||
),
|
||||
/// Property access - ((getter, hash), (setter, hash), prop)
|
||||
Property(Box<((Identifier, u64), (Identifier, u64), Ident)>),
|
||||
/// { [statement][Stmt] ... }
|
||||
@@ -1644,7 +1651,7 @@ impl Expr {
|
||||
#[inline(always)]
|
||||
pub(crate) fn get_variable_access(&self, non_qualified: bool) -> Option<&str> {
|
||||
match self {
|
||||
Self::Variable(x) if !non_qualified || x.1.is_none() => Some((x.2).name.as_str()),
|
||||
Self::Variable(_, x) if !non_qualified || x.1.is_none() => Some((x.2).name.as_str()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -1666,7 +1673,7 @@ impl Expr {
|
||||
Self::Map(_, pos) => *pos,
|
||||
Self::Property(x) => (x.2).pos,
|
||||
Self::Stmt(x) => x.pos,
|
||||
Self::Variable(x) => (x.2).pos,
|
||||
Self::Variable(_, x) => (x.2).pos,
|
||||
Self::FnCall(_, pos) => *pos,
|
||||
|
||||
Self::And(x, _) | Self::Or(x, _) => x.lhs.position(),
|
||||
@@ -1696,7 +1703,7 @@ impl Expr {
|
||||
Self::FnPointer(_, pos) => *pos = new_pos,
|
||||
Self::Array(_, pos) => *pos = new_pos,
|
||||
Self::Map(_, pos) => *pos = new_pos,
|
||||
Self::Variable(x) => (x.2).pos = new_pos,
|
||||
Self::Variable(_, x) => (x.2).pos = new_pos,
|
||||
Self::Property(x) => (x.2).pos = new_pos,
|
||||
Self::Stmt(x) => x.pos = new_pos,
|
||||
Self::FnCall(_, pos) => *pos = new_pos,
|
||||
@@ -1724,7 +1731,7 @@ impl Expr {
|
||||
|
||||
Self::Stmt(x) => x.statements.iter().all(Stmt::is_pure),
|
||||
|
||||
Self::Variable(_) => true,
|
||||
Self::Variable(_, _) => true,
|
||||
|
||||
_ => self.is_constant(),
|
||||
}
|
||||
@@ -1794,7 +1801,7 @@ impl Expr {
|
||||
_ => false,
|
||||
},
|
||||
|
||||
Self::Variable(_) => match token {
|
||||
Self::Variable(_, _) => match token {
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
Token::LeftBracket => true,
|
||||
Token::LeftParen => true,
|
||||
|
Reference in New Issue
Block a user