diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index ea634ea7c..abd373804 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -582,7 +582,7 @@ impl Scope<'_> { /// _(metadata, internals)_ Return definitions for all items inside the [`Scope`]. fn write_definition(&self, writer: &mut dyn fmt::Write, def: &Definitions) -> fmt::Result { let mut first = true; - for (name, constant, value) in self.iter_raw() { + for (name, constant, value) in self.iter_inner() { if !first { writer.write_str("\n\n")?; } diff --git a/src/func/script.rs b/src/func/script.rs index 3db62f482..443e410b1 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -80,7 +80,10 @@ impl Engine { #[cfg(feature = "debugging")] if self.is_debugger_registered() { let fn_name = fn_def.name.clone(); - let args = scope.iter().skip(orig_scope_len).map(|(.., v)| v); + let args = scope + .iter_inner() + .skip(orig_scope_len) + .map(|(.., v)| v.flatten_clone()); let source = global.source.clone(); global diff --git a/src/parser.rs b/src/parser.rs index 37d6534dd..5c3e12994 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2917,12 +2917,12 @@ impl Engine { // let name ... let (name, pos) = parse_var_name(input)?; - if !self.allow_shadowing() && state.stack.iter().any(|(v, ..)| v == name) { + if !self.allow_shadowing() && state.stack.get(&name).is_some() { return Err(PERR::VariableExists(name.into()).into_err(pos)); } if let Some(ref filter) = self.def_var_filter { - let will_shadow = state.stack.iter().any(|(v, ..)| v == name); + let will_shadow = state.stack.get(&name).is_some(); let global = state .global diff --git a/src/serde/serialize.rs b/src/serde/serialize.rs index 07638b5b6..ec3d4c27c 100644 --- a/src/serde/serialize.rs +++ b/src/serde/serialize.rs @@ -104,7 +104,7 @@ impl Serialize for Scope<'_> { let mut ser = ser.serialize_seq(Some(self.len()))?; - for (name, is_constant, value) in self.iter_raw() { + for (name, is_constant, value) in self.iter_inner() { let entry = ScopeEntry { name, value, diff --git a/src/types/scope.rs b/src/types/scope.rs index 8fff1ef88..fa15fa612 100644 --- a/src/types/scope.rs +++ b/src/types/scope.rs @@ -75,7 +75,7 @@ pub struct Scope<'a> { impl fmt::Display for Scope<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for (i, (name, constant, value)) in self.iter_raw().enumerate() { + for (i, (name, constant, value)) in self.iter_inner().enumerate() { #[cfg(not(feature = "no_closure"))] let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; #[cfg(feature = "no_closure")] @@ -912,19 +912,17 @@ impl Scope<'_> { /// assert!(is_constant); /// assert_eq!(value.cast::(), "hello"); /// ``` - #[inline] + #[inline(always)] pub fn iter(&self) -> impl Iterator { - self.iter_raw() - .map(|(name, constant, value)| (name, constant, value.flatten_clone())) + self.iter_inner() + .map(|(name, constant, value)| (name.as_str(), constant, value.flatten_clone())) } /// Get an iterator to entries in the [`Scope`]. /// Shared values are not expanded. - #[inline] + #[inline(always)] pub fn iter_raw(&self) -> impl Iterator { - self.names - .iter() - .zip(self.values.iter()) - .map(|(name, value)| (name.as_str(), value.is_read_only(), value)) + self.iter_rev_inner() + .map(|(name, constant, value)| (name.as_str(), constant, value)) } /// Get an iterator to entries in the [`Scope`]. /// Shared values are not expanded.