Remove unneeded strings interner for modules.

This commit is contained in:
Stephen Chung 2022-01-05 13:40:49 +08:00
parent 97295a66da
commit 2b613fdff3

View File

@ -7,7 +7,6 @@ use crate::func::{
}; };
use crate::tokenizer::Token; use crate::tokenizer::Token;
use crate::types::dynamic::Variant; use crate::types::dynamic::Variant;
use crate::types::StringsInterner;
use crate::{ use crate::{
calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, Identifier, calc_fn_params_hash, calc_qualified_fn_hash, combine_hashes, Dynamic, Identifier,
ImmutableString, NativeCallContext, RhaiResultOf, Shared, StaticVec, ImmutableString, NativeCallContext, RhaiResultOf, Shared, StaticVec,
@ -156,8 +155,6 @@ pub struct Module {
indexed: bool, indexed: bool,
/// Does the [`Module`] contain indexed functions that have been exposed to the global namespace? /// Does the [`Module`] contain indexed functions that have been exposed to the global namespace?
contains_indexed_global_functions: bool, contains_indexed_global_functions: bool,
/// Interned strings.
interner: StringsInterner,
} }
impl Default for Module { impl Default for Module {
@ -255,7 +252,6 @@ impl Module {
all_type_iterators: BTreeMap::new(), all_type_iterators: BTreeMap::new(),
indexed: true, indexed: true,
contains_indexed_global_functions: false, contains_indexed_global_functions: false,
interner: StringsInterner::new(),
} }
} }
@ -482,11 +478,7 @@ impl Module {
let num_params = fn_def.params.len(); let num_params = fn_def.params.len();
let hash_script = crate::calc_fn_hash(&fn_def.name, num_params); let hash_script = crate::calc_fn_hash(&fn_def.name, num_params);
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
let param_names_and_types = fn_def let param_names_and_types = fn_def.params.iter().cloned().collect();
.params
.iter()
.map(|v| self.interner.get("", v.as_str()).into())
.collect();
self.functions.insert( self.functions.insert(
hash_script, hash_script,
FuncInfo { FuncInfo {
@ -498,7 +490,7 @@ impl Module {
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
param_names_and_types, param_names_and_types,
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
return_type_name: self.interner.get("", "Dynamic").into(), return_type_name: "Dynamic".into(),
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
comments: None, comments: None,
func: Into::<CallableFunction>::into(fn_def).into(), func: Into::<CallableFunction>::into(fn_def).into(),
@ -652,7 +644,7 @@ impl Module {
let mut param_names: StaticVec<_> = arg_names let mut param_names: StaticVec<_> = arg_names
.as_ref() .as_ref()
.iter() .iter()
.map(|name| self.interner.get("", name.as_ref()).into()) .map(|s| s.as_ref().into())
.collect(); .collect();
if let Some(f) = self.functions.get_mut(&hash_fn) { if let Some(f) = self.functions.get_mut(&hash_fn) {
@ -787,7 +779,7 @@ impl Module {
let mut names = _arg_names let mut names = _arg_names
.iter() .iter()
.flat_map(|&p| p.iter()) .flat_map(|&p| p.iter())
.map(|&arg| self.interner.get("", arg).into()) .map(|&s| s.into())
.collect::<StaticVec<_>>(); .collect::<StaticVec<_>>();
let return_type = if names.len() > arg_types.as_ref().len() { let return_type = if names.len() > arg_types.as_ref().len() {
names.pop().expect("exists") names.pop().expect("exists")
@ -803,7 +795,7 @@ impl Module {
self.functions.insert( self.functions.insert(
hash_fn, hash_fn,
FuncInfo { FuncInfo {
name: self.interner.get("", name).into(), name: name.as_ref().into(),
namespace, namespace,
access, access,
params: param_types.len(), params: param_types.len(),
@ -1302,7 +1294,6 @@ impl Module {
self.all_type_iterators.clear(); self.all_type_iterators.clear();
self.indexed = false; self.indexed = false;
self.contains_indexed_global_functions = false; self.contains_indexed_global_functions = false;
self.interner += other.interner;
self self
} }
@ -1322,7 +1313,6 @@ impl Module {
self.all_type_iterators.clear(); self.all_type_iterators.clear();
self.indexed = false; self.indexed = false;
self.contains_indexed_global_functions = false; self.contains_indexed_global_functions = false;
self.interner += other.interner;
self self
} }
@ -1351,7 +1341,6 @@ impl Module {
self.all_type_iterators.clear(); self.all_type_iterators.clear();
self.indexed = false; self.indexed = false;
self.contains_indexed_global_functions = false; self.contains_indexed_global_functions = false;
self.interner += &other.interner;
self self
} }
@ -1401,7 +1390,6 @@ impl Module {
self.all_type_iterators.clear(); self.all_type_iterators.clear();
self.indexed = false; self.indexed = false;
self.contains_indexed_global_functions = false; self.contains_indexed_global_functions = false;
self.interner += &other.interner;
self self
} }