Remove unnecessary AsRef<str>.

This commit is contained in:
Stephen Chung 2021-07-10 10:11:14 +08:00
parent d517a0219b
commit 4d25fd0192
5 changed files with 15 additions and 14 deletions

View File

@ -209,7 +209,7 @@ fn main() {
.enumerate() .enumerate()
.for_each(|(i, (name, constant, value))| { .for_each(|(i, (name, constant, value))| {
#[cfg(not(feature = "no_closure"))] #[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")] #[cfg(feature = "no_closure")]
let value_is_shared = ""; let value_is_shared = "";

View File

@ -1901,6 +1901,7 @@ impl Engine {
let mut arg_values: crate::StaticVec<_> = Default::default(); let mut arg_values: crate::StaticVec<_> = Default::default();
args.parse(&mut arg_values); args.parse(&mut arg_values);
let mut args: crate::StaticVec<_> = arg_values.iter_mut().collect(); 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)?; 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 this_ptr: Option<&mut Dynamic>,
mut arg_values: impl AsMut<[Dynamic]>, mut arg_values: impl AsMut<[Dynamic]>,
) -> RhaiResult { ) -> RhaiResult {
let name = name.as_ref();
let mut args: crate::StaticVec<_> = arg_values.as_mut().iter_mut().collect(); 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) self.call_fn_dynamic_raw(scope, ast, eval_ast, name, &mut this_ptr, &mut args)
@ -2000,7 +2002,7 @@ impl Engine {
scope: &mut Scope, scope: &mut Scope,
ast: &AST, ast: &AST,
eval_ast: bool, eval_ast: bool,
name: impl AsRef<str>, name: &str,
this_ptr: &mut Option<&mut Dynamic>, this_ptr: &mut Option<&mut Dynamic>,
args: &mut FnCallArgs, args: &mut FnCallArgs,
) -> RhaiResult { ) -> RhaiResult {
@ -2008,7 +2010,6 @@ impl Engine {
let mods = &mut Default::default(); let mods = &mut Default::default();
let lib = &[ast.lib()]; let lib = &[ast.lib()];
let statements = ast.statements(); let statements = ast.statements();
let name = name.as_ref();
if eval_ast && !statements.is_empty() { if eval_ast && !statements.is_empty() {
self.eval_global_statements(scope, mods, state, statements, lib, 0)?; self.eval_global_statements(scope, mods, state, statements, lib, 0)?;

View File

@ -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. /// The first module name is skipped. Hashing starts from the _second_ module in the chain.
#[inline] #[inline]
#[must_use] #[must_use]
pub fn calc_qualified_var_hash<'a>( pub fn calc_qualified_var_hash<'a>(modules: impl Iterator<Item = &'a str>, var_name: &str) -> u64 {
modules: impl Iterator<Item = &'a str>,
var_name: impl AsRef<str>,
) -> u64 {
let s = &mut get_hasher(); let s = &mut get_hasher();
// We always skip the first module // We always skip the first module
@ -75,7 +72,7 @@ pub fn calc_qualified_var_hash<'a>(
.skip(1) .skip(1)
.for_each(|m| m.hash(s)); .for_each(|m| m.hash(s));
len.hash(s); len.hash(s);
var_name.as_ref().hash(s); var_name.hash(s);
s.finish() s.finish()
} }
@ -92,7 +89,7 @@ pub fn calc_qualified_var_hash<'a>(
#[must_use] #[must_use]
pub fn calc_qualified_fn_hash<'a>( pub fn calc_qualified_fn_hash<'a>(
modules: impl Iterator<Item = &'a str>, modules: impl Iterator<Item = &'a str>,
fn_name: impl AsRef<str>, fn_name: &str,
num: usize, num: usize,
) -> u64 { ) -> u64 {
let s = &mut get_hasher(); let s = &mut get_hasher();
@ -104,7 +101,7 @@ pub fn calc_qualified_fn_hash<'a>(
.skip(1) .skip(1)
.for_each(|m| m.hash(s)); .for_each(|m| m.hash(s));
len.hash(s); len.hash(s);
fn_name.as_ref().hash(s); fn_name.hash(s);
num.hash(s); num.hash(s);
s.finish() s.finish()
} }
@ -115,7 +112,7 @@ pub fn calc_qualified_fn_hash<'a>(
/// Parameter types are passed in via [`TypeId`] values from an iterator. /// Parameter types are passed in via [`TypeId`] values from an iterator.
#[inline(always)] #[inline(always)]
#[must_use] #[must_use]
pub fn calc_fn_hash(fn_name: impl AsRef<str>, num: usize) -> u64 { pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
calc_qualified_fn_hash(empty(), fn_name, num) calc_qualified_fn_hash(empty(), fn_name, num)
} }

View File

@ -115,7 +115,7 @@ impl FuncInfo {
#[inline(always)] #[inline(always)]
fn calc_native_fn_hash<'a>( fn calc_native_fn_hash<'a>(
modules: impl Iterator<Item = &'a str>, modules: impl Iterator<Item = &'a str>,
fn_name: impl AsRef<str>, fn_name: &str,
params: &[TypeId], params: &[TypeId],
) -> u64 { ) -> u64 {
let hash_script = calc_qualified_fn_hash(modules, fn_name, params.len()); let hash_script = calc_qualified_fn_hash(modules, fn_name, params.len());
@ -706,7 +706,7 @@ impl Module {
#[cfg(feature = "metadata")] #[cfg(feature = "metadata")]
param_names.shrink_to_fit(); param_names.shrink_to_fit();
let hash_fn = calc_native_fn_hash(empty(), &name, &param_types); let hash_fn = calc_native_fn_hash(empty(), name.as_ref(), &param_types);
self.functions.insert( self.functions.insert(
hash_fn, hash_fn,

View File

@ -1,6 +1,6 @@
//! Implementations of [`serde::Serialize`]. //! Implementations of [`serde::Serialize`].
use crate::dynamic::{Union, Variant}; use crate::dynamic::Union;
use crate::{Dynamic, ImmutableString}; use crate::{Dynamic, ImmutableString};
use serde::ser::{Serialize, Serializer}; use serde::ser::{Serialize, Serializer};
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
@ -9,6 +9,9 @@ use std::prelude::v1::*;
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
use serde::ser::SerializeMap; use serde::ser::SerializeMap;
#[cfg(not(feature = "no_std"))]
use crate::dynamic::Variant;
impl Serialize for Dynamic { impl Serialize for Dynamic {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self.0 { match self.0 {