Reduce size of ParseState.

This commit is contained in:
Stephen Chung 2022-11-24 17:08:43 +08:00
parent b4ef89b596
commit c9d8714fe6
7 changed files with 211 additions and 242 deletions

View File

@ -223,7 +223,7 @@ impl Engine {
self.token_mapper.as_ref().map(<_>::as_ref),
);
let interned_strings = &mut *locked_write(&self.interned_strings);
let mut state = ParseState::new(self, scope, interned_strings, tokenizer_control);
let mut state = ParseState::new(scope, interned_strings, tokenizer_control);
let mut _ast = self.parse(&mut stream.peekable(), &mut state, optimization_level)?;
#[cfg(feature = "metadata")]
_ast.set_doc(state.tokenizer_control.borrow().global_comments.join("\n"));
@ -297,7 +297,7 @@ impl Engine {
let mut peekable = stream.peekable();
let interned_strings = &mut *locked_write(&self.interned_strings);
let mut state = ParseState::new(self, scope, interned_strings, tokenizer_control);
let mut state = ParseState::new(scope, interned_strings, tokenizer_control);
self.parse_global_expr(&mut peekable, &mut state, |_| {}, self.optimization_level)
}
}

View File

@ -124,7 +124,7 @@ impl Engine {
let (stream, tokenizer_control) =
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref));
let mut state = ParseState::new(self, scope, interned_strings, tokenizer_control);
let mut state = ParseState::new(scope, interned_strings, tokenizer_control);
// No need to optimize a lone expression
self.parse_global_expr(

View File

@ -120,7 +120,7 @@ impl Engine {
let ast = {
let scope = Scope::new();
let interned_strings = &mut *locked_write(&self.interned_strings);
let mut state = ParseState::new(self, &scope, interned_strings, tokenizer_control);
let mut state = ParseState::new(&scope, interned_strings, tokenizer_control);
self.parse_global_expr(
&mut stream.peekable(),

View File

@ -63,7 +63,7 @@ impl Engine {
let (stream, tokenizer_control) =
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref));
let mut state = ParseState::new(self, scope, interned_strings, tokenizer_control);
let mut state = ParseState::new(scope, interned_strings, tokenizer_control);
self.parse(&mut stream.peekable(), &mut state, self.optimization_level)?
};

View File

@ -2,7 +2,7 @@
#![cfg(not(feature = "no_function"))]
use super::{FnAccess, StmtBlock};
use crate::{ImmutableString, StaticVec};
use crate::{FnArgsVec, ImmutableString};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
use std::{fmt, hash::Hash};
@ -42,7 +42,7 @@ pub struct ScriptFnDef {
/// Function access mode.
pub access: FnAccess,
/// Names of function parameters.
pub params: StaticVec<ImmutableString>,
pub params: FnArgsVec<ImmutableString>,
/// _(metadata)_ Function doc-comments (if any).
/// Exported under the `metadata` feature only.
///
@ -72,7 +72,7 @@ impl fmt::Display for ScriptFnDef {
self.params
.iter()
.map(|s| s.as_str())
.collect::<StaticVec<_>>()
.collect::<FnArgsVec<_>>()
.join(", ")
)
}
@ -121,7 +121,7 @@ impl fmt::Display for ScriptFnMetadata<'_> {
self.params
.iter()
.copied()
.collect::<StaticVec<_>>()
.collect::<FnArgsVec<_>>()
.join(", ")
)
}

File diff suppressed because it is too large Load Diff

View File

@ -70,14 +70,14 @@ impl StringsInterner {
#[must_use]
pub fn get_with_mapper<S: AsRef<str>>(
&mut self,
id: &str,
category: &str,
mapper: impl FnOnce(S) -> ImmutableString,
text: S,
) -> ImmutableString {
let key = text.as_ref();
let hasher = &mut get_hasher();
id.hash(hasher);
category.hash(hasher);
key.hash(hasher);
let hash = hasher.finish();