From d88e17d177632d1041eb41fa7f38c2afffe213d2 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 28 Nov 2021 12:41:20 +0800 Subject: [PATCH] Move more &str to AsRef --- src/func/hashing.rs | 17 ++++++++++------- src/module/mod.rs | 6 +++--- src/tokenizer.rs | 4 ++-- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/func/hashing.rs b/src/func/hashing.rs index 86931c82..d0ede330 100644 --- a/src/func/hashing.rs +++ b/src/func/hashing.rs @@ -62,7 +62,10 @@ 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: &str) -> u64 { +pub fn calc_qualified_var_hash<'a>( + modules: impl Iterator + 'a>, + var_name: impl AsRef, +) -> u64 { let s = &mut get_hasher(); // We always skip the first module @@ -70,9 +73,9 @@ pub fn calc_qualified_var_hash<'a>(modules: impl Iterator, var_n modules .inspect(|_| len += 1) .skip(1) - .for_each(|m| m.hash(s)); + .for_each(|m| m.as_ref().hash(s)); len.hash(s); - var_name.hash(s); + var_name.as_ref().hash(s); s.finish() } @@ -87,8 +90,8 @@ pub fn calc_qualified_var_hash<'a>(modules: impl Iterator, var_n /// The first module name is skipped. Hashing starts from the _second_ module in the chain. #[inline] #[must_use] -pub fn calc_qualified_fn_hash<'a>( - modules: impl Iterator, +pub fn calc_qualified_fn_hash( + modules: impl Iterator>, fn_name: impl AsRef, num: usize, ) -> u64 { @@ -99,7 +102,7 @@ pub fn calc_qualified_fn_hash<'a>( modules .inspect(|_| len += 1) .skip(1) - .for_each(|m| m.hash(s)); + .for_each(|m| m.as_ref().hash(s)); len.hash(s); fn_name.as_ref().hash(s); num.hash(s); @@ -113,7 +116,7 @@ pub fn calc_qualified_fn_hash<'a>( #[inline(always)] #[must_use] pub fn calc_fn_hash(fn_name: impl AsRef, num: usize) -> u64 { - calc_qualified_fn_hash(empty(), fn_name, num) + calc_qualified_fn_hash(empty::<&str>(), fn_name, num) } /// Calculate a [`u64`] hash key from a list of parameter types. diff --git a/src/module/mod.rs b/src/module/mod.rs index 0511f042..5479d087 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -107,8 +107,8 @@ impl FuncInfo { /// /// The first module name is skipped. Hashing starts from the _second_ module in the chain. #[inline] -fn calc_native_fn_hash<'a>( - modules: impl Iterator, +fn calc_native_fn_hash( + modules: impl Iterator>, fn_name: impl AsRef, params: &[TypeId], ) -> u64 { @@ -711,7 +711,7 @@ impl Module { #[cfg(feature = "metadata")] param_names.shrink_to_fit(); - let hash_fn = calc_native_fn_hash(empty(), name.as_ref(), ¶m_types); + let hash_fn = calc_native_fn_hash(empty::<&str>(), name.as_ref(), ¶m_types); self.functions.insert( hash_fn, diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 3fa2dc5f..968b66e5 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -2269,7 +2269,7 @@ impl Engine { #[must_use] pub fn lex<'a>( &'a self, - input: impl IntoIterator, + input: impl IntoIterator + 'a)>, ) -> (TokenIterator<'a>, TokenizerControl) { self.lex_raw(input, None) } @@ -2280,7 +2280,7 @@ impl Engine { #[must_use] pub fn lex_with_map<'a>( &'a self, - input: impl IntoIterator, + input: impl IntoIterator + 'a)>, token_mapper: &'a OnParseTokenCallback, ) -> (TokenIterator<'a>, TokenizerControl) { self.lex_raw(input, Some(token_mapper))