use crate::func::{RhaiFunc, 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: RhaiFunc,
pub source: Option<ImmutableString>,
}
#[derive(Debug, Clone, Default)]
pub struct FnResolutionCache {
pub dict: StraightHashMap<Option<FnResolutionCacheEntry>>,
pub bloom_filter: BloomFilterU64,
}
impl FnResolutionCache {
#[inline(always)]
#[allow(dead_code)]
pub fn clear(&mut self) {
self.dict.clear();
self.bloom_filter.clear();
}
}
#[derive(Debug, Clone, Default)]
pub struct Caches {
fn_resolution: StaticVec<FnResolutionCache>,
}
impl Caches {
#[inline(always)]
#[must_use]
pub const fn new() -> Self {
Self {
fn_resolution: StaticVec::new_const(),
}
}
#[inline(always)]
#[must_use]
pub fn fn_resolution_caches_len(&self) -> usize {
self.fn_resolution.len()
}
#[inline]
#[must_use]
pub fn fn_resolution_cache_mut(&mut self) -> &mut FnResolutionCache {
if self.fn_resolution.is_empty() {
self.push_fn_resolution_cache();
}
self.fn_resolution.last_mut().unwrap()
}
#[inline(always)]
pub fn push_fn_resolution_cache(&mut self) {
self.fn_resolution.push(<_>::default());
}
#[inline(always)]
pub fn rewind_fn_resolution_caches(&mut self, len: usize) {
self.fn_resolution.truncate(len);
}
}