use crate::func::{CallableFunction, StraightHashMap};
use crate::types::BloomFilterU64;
use crate::{ImmutableString, StaticVec};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[derive(Debug, Clone)]
pub struct FnResolutionCacheEntry {
pub func: CallableFunction,
pub source: Option<ImmutableString>,
}
#[derive(Debug, Clone, Default)]
pub struct FnResolutionCache {
pub map: StraightHashMap<Option<FnResolutionCacheEntry>>,
pub filter: BloomFilterU64,
}
impl FnResolutionCache {
#[inline(always)]
pub fn clear(&mut self) {
self.map.clear();
self.filter.clear();
}
}
#[derive(Debug, Clone)]
pub struct Caches(StaticVec<FnResolutionCache>);
impl Caches {
#[inline(always)]
#[must_use]
pub const fn new() -> Self {
Self(StaticVec::new_const())
}
#[inline(always)]
#[must_use]
pub fn fn_resolution_caches_len(&self) -> usize {
self.0.len()
}
#[inline]
#[must_use]
pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache {
if self.0.is_empty() {
self.push_fn_resolution_cache();
}
self.0.last_mut().unwrap()
}
#[inline(always)]
pub fn push_fn_resolution_cache(&mut self) {
self.0.push(FnResolutionCache::default());
}
#[inline(always)]
pub fn rewind_fn_resolution_caches(&mut self, len: usize) {
self.0.truncate(len);
}
}