Split calc_qualified_var_hash.

This commit is contained in:
Stephen Chung
2021-06-30 16:28:37 +08:00
parent f033896fec
commit a0f51a1a39
4 changed files with 35 additions and 8 deletions

View File

@@ -52,6 +52,33 @@ pub fn get_hasher() -> ahash::AHasher {
Default::default()
}
/// Calculate a [`u64`] hash key from a namespace-qualified variable name.
///
/// Module names are passed in via `&str` references from an iterator.
/// Parameter types are passed in via [`TypeId`] values from an iterator.
///
/// # Note
///
/// 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 {
let s = &mut get_hasher();
// We always skip the first module
let mut len = 0;
modules
.inspect(|_| len += 1)
.skip(1)
.for_each(|m| m.hash(s));
len.hash(s);
var_name.as_ref().hash(s);
s.finish()
}
/// Calculate a [`u64`] hash key from a namespace-qualified function name
/// and the number of parameters, but no parameter types.
///