Unify function hash calculations, pre-hash module-qualified function calls.

This commit is contained in:
Stephen Chung
2020-05-08 11:34:56 +08:00
parent 5f12391ec6
commit e6fabe58cc
5 changed files with 130 additions and 89 deletions

View File

@@ -14,6 +14,10 @@ use crate::stdlib::collections::hash_map::DefaultHasher;
#[cfg(feature = "no_std")]
use ahash::AHasher;
pub fn EMPTY_TYPE_ID() -> TypeId {
TypeId::of::<()>()
}
/// Calculate a `u64` hash key from a module-qualified function name and parameter types.
///
/// Module names are passed in via `&str` references from an iterator.
@@ -39,18 +43,6 @@ pub fn calc_fn_spec<'a>(
s.finish()
}
/// Calculate a `u64` hash key from a function name and number of parameters (without regard to types).
pub(crate) fn calc_fn_def(fn_name: &str, num_params: usize) -> u64 {
#[cfg(feature = "no_std")]
let mut s: AHasher = Default::default();
#[cfg(not(feature = "no_std"))]
let mut s = DefaultHasher::new();
s.write(fn_name.as_bytes());
s.write_usize(num_params);
s.finish()
}
/// A type to hold a number of values in static storage for speed, and any spill-overs in a `Vec`.
///
/// This is essentially a knock-off of the [`staticvec`](https://crates.io/crates/staticvec) crate.