use crate::func::{CallableFunction, StraightHashMap};
use crate::types::BloomFilterU64;
use crate::{Identifier, StaticVec};
use std::marker::PhantomData;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
#[derive(Debug, Clone)]
pub struct FnResolutionCacheEntry {
pub func: CallableFunction,
pub source: Option<Box<Identifier>>,
}
#[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<'a> {
stack: StaticVec<FnResolutionCache>,
dummy: PhantomData<&'a ()>,
}
impl Caches<'_> {
#[inline(always)]
#[must_use]
pub const fn new() -> Self {
Self {
stack: StaticVec::new_const(),
dummy: PhantomData,
}
}
#[inline(always)]
#[must_use]
pub fn fn_resolution_caches_len(&self) -> usize {
self.stack.len()
}
#[inline]
#[must_use]
pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache {
if self.stack.is_empty() {
self.push_fn_resolution_cache();
}
self.stack.last_mut().unwrap()
}
#[inline(always)]
pub fn push_fn_resolution_cache(&mut self) {
self.stack.push(Default::default());
}
#[inline(always)]
pub fn rewind_fn_resolution_caches(&mut self, len: usize) {
self.stack.truncate(len);
}
}