Remove key type from StraightHashMap.
This commit is contained in:
parent
08f6682d09
commit
40a12b2b7d
@ -20,12 +20,12 @@ pub struct FnResolutionCacheEntry {
|
||||
/// _(internals)_ A function resolution cache with a bloom filter.
|
||||
/// Exported under the `internals` feature only.
|
||||
///
|
||||
/// [`FnResolutionCacheEntry`] is [`Box`]ed in order to pack as many entries inside a single B-Tree
|
||||
/// level as possible.
|
||||
/// The bloom filter is used to rapidly check whether a function hash has never been encountered.
|
||||
/// It enables caching a hash only during the second encounter to avoid "one-hit wonders".
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct FnResolutionCache {
|
||||
/// Hash map containing cached functions.
|
||||
pub map: StraightHashMap<u64, Option<FnResolutionCacheEntry>>,
|
||||
pub map: StraightHashMap<Option<FnResolutionCacheEntry>>,
|
||||
/// Bloom filter to avoid caching "one-hit wonders".
|
||||
pub filter: BloomFilterU64,
|
||||
}
|
||||
@ -47,7 +47,7 @@ impl FnResolutionCache {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Caches<'a> {
|
||||
/// Stack of [function resolution caches][FnResolutionCache].
|
||||
fn_resolution_caches: StaticVec<FnResolutionCache>,
|
||||
stack: StaticVec<FnResolutionCache>,
|
||||
/// Take care of the lifetime parameter.
|
||||
dummy: PhantomData<&'a ()>,
|
||||
}
|
||||
@ -58,7 +58,7 @@ impl Caches<'_> {
|
||||
#[must_use]
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
fn_resolution_caches: StaticVec::new_const(),
|
||||
stack: StaticVec::new_const(),
|
||||
dummy: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -66,27 +66,27 @@ impl Caches<'_> {
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
pub fn fn_resolution_caches_len(&self) -> usize {
|
||||
self.fn_resolution_caches.len()
|
||||
self.stack.len()
|
||||
}
|
||||
/// Get a mutable reference to the current function resolution cache.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache {
|
||||
if self.fn_resolution_caches.is_empty() {
|
||||
if self.stack.is_empty() {
|
||||
// Push a new function resolution cache if the stack is empty
|
||||
self.push_fn_resolution_cache();
|
||||
}
|
||||
self.fn_resolution_caches.last_mut().unwrap()
|
||||
self.stack.last_mut().unwrap()
|
||||
}
|
||||
/// Push an empty function resolution cache onto the stack and make it current.
|
||||
#[allow(dead_code)]
|
||||
#[inline(always)]
|
||||
pub fn push_fn_resolution_cache(&mut self) {
|
||||
self.fn_resolution_caches.push(Default::default());
|
||||
self.stack.push(Default::default());
|
||||
}
|
||||
/// Rewind the function resolution caches stack to a particular size.
|
||||
#[inline(always)]
|
||||
pub fn rewind_fn_resolution_caches(&mut self, len: usize) {
|
||||
self.fn_resolution_caches.truncate(len);
|
||||
self.stack.truncate(len);
|
||||
}
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ use std::{
|
||||
};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
pub type StraightHashMap<K, V> = hashbrown::HashMap<K, V, StraightHasherBuilder>;
|
||||
pub type StraightHashMap<V> = hashbrown::HashMap<u64, V, StraightHasherBuilder>;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
pub type StraightHashMap<K, V> = std::collections::HashMap<K, V, StraightHasherBuilder>;
|
||||
pub type StraightHashMap<V> = std::collections::HashMap<u64, V, StraightHasherBuilder>;
|
||||
|
||||
/// Dummy hash value to map zeros to. This value can be anything.
|
||||
///
|
||||
|
@ -176,12 +176,12 @@ pub struct Module {
|
||||
/// [`Module`] variables.
|
||||
variables: BTreeMap<Identifier, Dynamic>,
|
||||
/// Flattened collection of all [`Module`] variables, including those in sub-modules.
|
||||
all_variables: StraightHashMap<u64, Dynamic>,
|
||||
all_variables: StraightHashMap<Dynamic>,
|
||||
/// Functions (both native Rust and scripted).
|
||||
functions: StraightHashMap<u64, Box<FuncInfo>>,
|
||||
functions: StraightHashMap<Box<FuncInfo>>,
|
||||
/// Flattened collection of all functions, native Rust and scripted.
|
||||
/// including those in sub-modules.
|
||||
all_functions: StraightHashMap<u64, CallableFunction>,
|
||||
all_functions: StraightHashMap<CallableFunction>,
|
||||
/// Native Rust functions (in scripted hash format) that contain [`Dynamic`] parameters.
|
||||
dynamic_functions: BloomFilterU64,
|
||||
/// Iterator functions, keyed by the type producing the iterator.
|
||||
@ -2025,8 +2025,8 @@ impl Module {
|
||||
fn index_module<'a>(
|
||||
module: &'a Module,
|
||||
path: &mut Vec<&'a str>,
|
||||
variables: &mut StraightHashMap<u64, Dynamic>,
|
||||
functions: &mut StraightHashMap<u64, CallableFunction>,
|
||||
variables: &mut StraightHashMap<Dynamic>,
|
||||
functions: &mut StraightHashMap<CallableFunction>,
|
||||
type_iterators: &mut BTreeMap<TypeId, Shared<IteratorFn>>,
|
||||
) -> bool {
|
||||
let mut contains_indexed_global_functions = false;
|
||||
|
@ -32,7 +32,7 @@ use std::{
|
||||
|
||||
pub type ParseResult<T> = Result<T, ParseError>;
|
||||
|
||||
type FnLib = StraightHashMap<u64, Shared<ScriptFnDef>>;
|
||||
type FnLib = StraightHashMap<Shared<ScriptFnDef>>;
|
||||
|
||||
const KEYWORD_SEMICOLON: &str = Token::SemiColon.literal_syntax();
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub struct StringsInterner<'a> {
|
||||
/// Maximum string length.
|
||||
pub max_string_len: usize,
|
||||
/// Normal strings.
|
||||
strings: StraightHashMap<u64, ImmutableString>,
|
||||
strings: StraightHashMap<ImmutableString>,
|
||||
/// Take care of the lifetime parameter.
|
||||
dummy: PhantomData<&'a ()>,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user