From 4d25fd019289ff259b40ef00f683602790d0a138 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sat, 10 Jul 2021 10:11:14 +0800 Subject: [PATCH] Remove unnecessary AsRef. --- src/bin/rhai-repl.rs | 2 +- src/engine_api.rs | 5 +++-- src/fn_hash.rs | 13 +++++-------- src/module/mod.rs | 4 ++-- src/serde/serialize.rs | 5 ++++- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/bin/rhai-repl.rs b/src/bin/rhai-repl.rs index 2a11f76f..af322021 100644 --- a/src/bin/rhai-repl.rs +++ b/src/bin/rhai-repl.rs @@ -209,7 +209,7 @@ fn main() { .enumerate() .for_each(|(i, (name, constant, value))| { #[cfg(not(feature = "no_closure"))] - let value_is_shared = if value.is_shared() { " (shared" } else { "" }; + let value_is_shared = if value.is_shared() { " (shared)" } else { "" }; #[cfg(feature = "no_closure")] let value_is_shared = ""; diff --git a/src/engine_api.rs b/src/engine_api.rs index ab896a2a..a7a28177 100644 --- a/src/engine_api.rs +++ b/src/engine_api.rs @@ -1901,6 +1901,7 @@ impl Engine { let mut arg_values: crate::StaticVec<_> = Default::default(); args.parse(&mut arg_values); let mut args: crate::StaticVec<_> = arg_values.iter_mut().collect(); + let name = name.as_ref(); let result = self.call_fn_dynamic_raw(scope, ast, true, name, &mut None, &mut args)?; @@ -1980,6 +1981,7 @@ impl Engine { mut this_ptr: Option<&mut Dynamic>, mut arg_values: impl AsMut<[Dynamic]>, ) -> RhaiResult { + let name = name.as_ref(); let mut args: crate::StaticVec<_> = arg_values.as_mut().iter_mut().collect(); self.call_fn_dynamic_raw(scope, ast, eval_ast, name, &mut this_ptr, &mut args) @@ -2000,7 +2002,7 @@ impl Engine { scope: &mut Scope, ast: &AST, eval_ast: bool, - name: impl AsRef, + name: &str, this_ptr: &mut Option<&mut Dynamic>, args: &mut FnCallArgs, ) -> RhaiResult { @@ -2008,7 +2010,6 @@ impl Engine { let mods = &mut Default::default(); let lib = &[ast.lib()]; let statements = ast.statements(); - let name = name.as_ref(); if eval_ast && !statements.is_empty() { self.eval_global_statements(scope, mods, state, statements, lib, 0)?; diff --git a/src/fn_hash.rs b/src/fn_hash.rs index 887ebceb..1a20d02a 100644 --- a/src/fn_hash.rs +++ b/src/fn_hash.rs @@ -62,10 +62,7 @@ pub fn get_hasher() -> ahash::AHasher { /// The first module name is skipped. Hashing starts from the _second_ module in the chain. #[inline] #[must_use] -pub fn calc_qualified_var_hash<'a>( - modules: impl Iterator, - var_name: impl AsRef, -) -> u64 { +pub fn calc_qualified_var_hash<'a>(modules: impl Iterator, var_name: &str) -> u64 { let s = &mut get_hasher(); // We always skip the first module @@ -75,7 +72,7 @@ pub fn calc_qualified_var_hash<'a>( .skip(1) .for_each(|m| m.hash(s)); len.hash(s); - var_name.as_ref().hash(s); + var_name.hash(s); s.finish() } @@ -92,7 +89,7 @@ pub fn calc_qualified_var_hash<'a>( #[must_use] pub fn calc_qualified_fn_hash<'a>( modules: impl Iterator, - fn_name: impl AsRef, + fn_name: &str, num: usize, ) -> u64 { let s = &mut get_hasher(); @@ -104,7 +101,7 @@ pub fn calc_qualified_fn_hash<'a>( .skip(1) .for_each(|m| m.hash(s)); len.hash(s); - fn_name.as_ref().hash(s); + fn_name.hash(s); num.hash(s); s.finish() } @@ -115,7 +112,7 @@ pub fn calc_qualified_fn_hash<'a>( /// Parameter types are passed in via [`TypeId`] values from an iterator. #[inline(always)] #[must_use] -pub fn calc_fn_hash(fn_name: impl AsRef, num: usize) -> u64 { +pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 { calc_qualified_fn_hash(empty(), fn_name, num) } diff --git a/src/module/mod.rs b/src/module/mod.rs index 1ff6e4a8..ddcd7d3c 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -115,7 +115,7 @@ impl FuncInfo { #[inline(always)] fn calc_native_fn_hash<'a>( modules: impl Iterator, - fn_name: impl AsRef, + fn_name: &str, params: &[TypeId], ) -> u64 { let hash_script = calc_qualified_fn_hash(modules, fn_name, params.len()); @@ -706,7 +706,7 @@ impl Module { #[cfg(feature = "metadata")] param_names.shrink_to_fit(); - let hash_fn = calc_native_fn_hash(empty(), &name, ¶m_types); + let hash_fn = calc_native_fn_hash(empty(), name.as_ref(), ¶m_types); self.functions.insert( hash_fn, diff --git a/src/serde/serialize.rs b/src/serde/serialize.rs index 1bf93383..560d489d 100644 --- a/src/serde/serialize.rs +++ b/src/serde/serialize.rs @@ -1,6 +1,6 @@ //! Implementations of [`serde::Serialize`]. -use crate::dynamic::{Union, Variant}; +use crate::dynamic::Union; use crate::{Dynamic, ImmutableString}; use serde::ser::{Serialize, Serializer}; #[cfg(feature = "no_std")] @@ -9,6 +9,9 @@ use std::prelude::v1::*; #[cfg(not(feature = "no_object"))] use serde::ser::SerializeMap; +#[cfg(not(feature = "no_std"))] +use crate::dynamic::Variant; + impl Serialize for Dynamic { fn serialize(&self, ser: S) -> Result { match self.0 {