Use tokens to speed up function name lookup.

This commit is contained in:
Stephen Chung
2022-09-25 23:03:18 +08:00
parent ece522ce2f
commit bf02d040e2
15 changed files with 417 additions and 349 deletions

View File

@@ -193,7 +193,7 @@ pub struct FnCallExpr {
/// Does this function call capture the parent scope?
pub capture_parent_scope: bool,
/// Is this function call a native operator?
pub is_native_operator: bool,
pub operator_token: Option<Token>,
/// [Position] of the function name.
pub pos: Position,
}
@@ -208,8 +208,8 @@ impl fmt::Debug for FnCallExpr {
if self.capture_parent_scope {
ff.field("capture_parent_scope", &self.capture_parent_scope);
}
if self.is_native_operator {
ff.field("is_native_operator", &self.is_native_operator);
if let Some(ref token) = self.operator_token {
ff.field("operator_token", token);
}
ff.field("hash", &self.hashes)
.field("name", &self.name)
@@ -673,7 +673,7 @@ impl Expr {
hashes: calc_fn_hash(None, f.fn_name(), 1).into(),
args: once(Self::StringConstant(f.fn_name().into(), pos)).collect(),
capture_parent_scope: false,
is_native_operator: false,
operator_token: None,
pos,
}
.into(),

View File

@@ -19,16 +19,16 @@ use std::{
/// Exported under the `internals` feature only.
///
/// This type may hold a straight assignment (i.e. not an op-assignment).
#[derive(Clone, Copy, Eq, PartialEq, Hash)]
#[derive(Clone, PartialEq, Hash)]
pub struct OpAssignment {
/// Hash of the op-assignment call.
pub hash_op_assign: u64,
/// Hash of the underlying operator call (for fallback).
pub hash_op: u64,
/// Op-assignment operator.
pub op_assign: &'static str,
pub op_assign: Token,
/// Underlying operator.
pub op: &'static str,
pub op: Token,
/// [Position] of the op-assignment operator.
pub pos: Position,
}
@@ -41,8 +41,8 @@ impl OpAssignment {
Self {
hash_op_assign: 0,
hash_op: 0,
op_assign: "=",
op: "=",
op_assign: Token::Equals,
op: Token::Equals,
pos,
}
}
@@ -71,12 +71,11 @@ impl OpAssignment {
pub fn new_op_assignment_from_token(op: &Token, pos: Position) -> Self {
let op_raw = op
.get_base_op_from_assignment()
.expect("op-assignment operator")
.literal_syntax();
.expect("op-assignment operator");
Self {
hash_op_assign: calc_fn_hash(None, op.literal_syntax(), 2),
hash_op: calc_fn_hash(None, op_raw, 2),
op_assign: op.literal_syntax(),
hash_op: calc_fn_hash(None, op_raw.literal_syntax(), 2),
op_assign: op.clone(),
op: op_raw,
pos,
}