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()
.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 = "";

View File

@ -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<str>,
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)?;

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.
#[inline]
#[must_use]
pub fn calc_qualified_var_hash<'a>(
modules: impl Iterator<Item = &'a str>,
var_name: impl AsRef<str>,
) -> u64 {
pub fn calc_qualified_var_hash<'a>(modules: impl Iterator<Item = &'a str>, 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<Item = &'a str>,
fn_name: impl AsRef<str>,
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<str>, num: usize) -> u64 {
pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
calc_qualified_fn_hash(empty(), fn_name, num)
}

View File

@ -115,7 +115,7 @@ impl FuncInfo {
#[inline(always)]
fn calc_native_fn_hash<'a>(
modules: impl Iterator<Item = &'a str>,
fn_name: impl AsRef<str>,
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, &param_types);
let hash_fn = calc_native_fn_hash(empty(), name.as_ref(), &param_types);
self.functions.insert(
hash_fn,

View File

@ -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<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {
match self.0 {