diff --git a/src/engine.rs b/src/engine.rs index 84c85701..3520108f 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -304,7 +304,7 @@ impl Engine { }; // Add the global namespace module - let mut global_namespace = Module::new(); + let mut global_namespace = Module::with_capacity(0); global_namespace.internal = true; engine.global_modules.push(global_namespace.into()); diff --git a/src/module/mod.rs b/src/module/mod.rs index 68fbdbbf..bbff05d5 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -270,27 +270,10 @@ impl Module { /// module.set_var("answer", 42_i64); /// assert_eq!(module.get_var_value::("answer").expect("answer should exist"), 42); /// ``` - #[inline] + #[inline(always)] #[must_use] pub fn new() -> Self { - Self { - id: Identifier::new_const(), - #[cfg(feature = "metadata")] - doc: crate::SmartString::new_const(), - internal: false, - standard: false, - custom_types: None, - modules: None, - variables: None, - all_variables: None, - functions: StraightHashMap::default(), - all_functions: None, - dynamic_functions: BloomFilterU64::new(), - type_iterators: None, - all_type_iterators: None, - indexed: true, - contains_indexed_global_functions: false, - } + Self::with_capacity(16) } /// Create a new [`Module`] with a pre-sized capacity for functions. /// @@ -486,7 +469,7 @@ impl Module { #[inline(always)] pub fn set_custom_type(&mut self, name: &str) -> &mut Self { self.custom_types - .get_or_insert_with(|| Default::default()) + .get_or_insert_with(CustomTypesCollection::new) .add_type::(name); self } @@ -512,7 +495,7 @@ impl Module { name: impl Into, ) -> &mut Self { self.custom_types - .get_or_insert_with(|| Default::default()) + .get_or_insert_with(CustomTypesCollection::new) .add(type_name, name); self } @@ -1752,7 +1735,7 @@ impl Module { if let Some(ref mut m) = self.modules { m.extend(modules.iter().map(|(k, v)| (k.clone(), v.clone()))); } else { - m = modules.clone(); + self.modules = Some(modules.clone()); } } diff --git a/src/packages/lang_core.rs b/src/packages/lang_core.rs index 25cfaee0..5eaa5ea3 100644 --- a/src/packages/lang_core.rs +++ b/src/packages/lang_core.rs @@ -1,7 +1,7 @@ use crate::def_package; use crate::plugin::*; use crate::types::dynamic::Tag; -use crate::{Dynamic, RhaiResultOf, ERR, INT, MAX_USIZE_INT}; +use crate::{Dynamic, RhaiResultOf, ERR, INT}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -113,7 +113,7 @@ mod reflection_functions { } #[rhai_fn(name = "get_fn_metadata_list")] pub fn get_fn_metadata2(ctx: NativeCallContext, name: &str, params: INT) -> crate::Array { - if params < 0 || params > MAX_USIZE_INT { + if params < 0 || params > crate::MAX_USIZE_INT { crate::Array::new() } else { collect_fn_metadata(ctx, |_, _, n, p, _| p == (params as usize) && n == name) diff --git a/src/types/custom_types.rs b/src/types/custom_types.rs index b0cb8bfd..3b759edc 100644 --- a/src/types/custom_types.rs +++ b/src/types/custom_types.rs @@ -29,11 +29,6 @@ impl CustomTypesCollection { pub fn new() -> Self { Self(BTreeMap::new()) } - /// Clear the [`CustomTypesCollection`]. - #[inline(always)] - pub fn clear(&mut self) { - self.0.clear(); - } /// Register a custom type. #[inline(always)] pub fn add(&mut self, type_name: impl Into, name: impl Into) {