pref: use ExactSizeIterator

This commit is contained in:
quake 2022-09-06 14:16:15 +09:00
parent ab23094d65
commit 563f18a04b
2 changed files with 15 additions and 19 deletions

View File

@ -96,18 +96,15 @@ pub fn get_hasher() -> ahash::AHasher {
#[inline] #[inline]
#[must_use] #[must_use]
pub fn calc_qualified_var_hash<'a>( pub fn calc_qualified_var_hash<'a>(
modules: impl IntoIterator<Item = &'a str>, modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
var_name: &str, var_name: &str,
) -> u64 { ) -> u64 {
let s = &mut get_hasher(); let s = &mut get_hasher();
// We always skip the first module // We always skip the first module
let mut len = 0; let iter = modules.into_iter();
modules let len = iter.len();
.into_iter() iter.skip(1).for_each(|m| m.hash(s));
.inspect(|_| len += 1)
.skip(1)
.for_each(|m| m.hash(s));
len.hash(s); len.hash(s);
var_name.hash(s); var_name.hash(s);
@ -133,19 +130,16 @@ pub fn calc_qualified_var_hash<'a>(
#[inline] #[inline]
#[must_use] #[must_use]
pub fn calc_qualified_fn_hash<'a>( pub fn calc_qualified_fn_hash<'a>(
modules: impl IntoIterator<Item = &'a str>, modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
fn_name: &str, fn_name: &str,
num: usize, num: usize,
) -> u64 { ) -> u64 {
let s = &mut get_hasher(); let s = &mut get_hasher();
// We always skip the first module // We always skip the first module
let mut len = 0; let iter = modules.into_iter();
modules let len = iter.len();
.into_iter() iter.skip(1).for_each(|m| m.hash(s));
.inspect(|_| len += 1)
.skip(1)
.for_each(|m| m.hash(s));
len.hash(s); len.hash(s);
fn_name.hash(s); fn_name.hash(s);
num.hash(s); num.hash(s);
@ -179,11 +173,13 @@ pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
/// If the hash happens to be zero, it is mapped to `DEFAULT_HASH`. /// If the hash happens to be zero, it is mapped to `DEFAULT_HASH`.
#[inline] #[inline]
#[must_use] #[must_use]
pub fn calc_fn_params_hash(params: impl IntoIterator<Item = TypeId>) -> u64 { pub fn calc_fn_params_hash(
params: impl IntoIterator<Item = TypeId, IntoIter = impl ExactSizeIterator<Item = TypeId>>,
) -> u64 {
let s = &mut get_hasher(); let s = &mut get_hasher();
let mut len = 0; let iter = params.into_iter();
params.into_iter().for_each(|t| { let len = iter.len();
len += 1; iter.for_each(|t| {
t.hash(s); t.hash(s);
}); });
len.hash(s); len.hash(s);

View File

@ -239,7 +239,7 @@ impl FuncInfo {
/// 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]
pub fn calc_native_fn_hash<'a>( pub fn calc_native_fn_hash<'a>(
modules: impl IntoIterator<Item = &'a str>, modules: impl IntoIterator<Item = &'a str, IntoIter = impl ExactSizeIterator<Item = &'a str>>,
fn_name: &str, fn_name: &str,
params: &[TypeId], params: &[TypeId],
) -> u64 { ) -> u64 {