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

View File

@ -124,7 +124,7 @@ impl Engine {
let (stream, tokenizer_control) = let (stream, tokenizer_control) =
self.lex_raw(&scripts, self.token_mapper.as_ref().map(<_>::as_ref)); 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 // No need to optimize a lone expression
self.parse_global_expr( self.parse_global_expr(

View File

@ -120,7 +120,7 @@ impl Engine {
let ast = { let ast = {
let scope = Scope::new(); let scope = Scope::new();
let interned_strings = &mut *locked_write(&self.interned_strings); 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( self.parse_global_expr(
&mut stream.peekable(), &mut stream.peekable(),

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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