use rustc_hash::FxHashMap;
use std::sync::Arc;
use super::EntityDecoder;
use crate::DecodedEntity;
impl EntityDecoder<'_> {
pub fn drain_cache(&mut self) -> FxHashMap<u32, Arc<DecodedEntity>> {
std::mem::take(&mut self.cache)
}
pub fn clear_cache(&mut self) {
self.cache.clear();
self.point_cache.clear();
self.placement_transform_cache.clear();
}
pub fn clear_entity_cache(&mut self) {
self.cache.clear();
}
pub fn clear_point_cache(&mut self) {
self.point_cache.clear();
}
pub fn take_point_cache(&mut self) -> FxHashMap<u32, (f64, f64, f64)> {
std::mem::take(&mut self.point_cache)
}
pub fn set_point_cache(&mut self, cache: FxHashMap<u32, (f64, f64, f64)>) {
self.point_cache = cache;
}
pub fn point_cache_stats(&self) -> (u64, u64) {
(self.point_cache_hits, self.point_cache_misses)
}
pub fn take_placement_transform_cache(&mut self) -> FxHashMap<u32, [f64; 16]> {
std::mem::take(&mut self.placement_transform_cache)
}
pub fn set_placement_transform_cache(&mut self, cache: FxHashMap<u32, [f64; 16]>) {
self.placement_transform_cache = cache;
}
pub fn get_placement_transform_cached(&self, id: u32) -> Option<[f64; 16]> {
self.placement_transform_cache.get(&id).copied()
}
pub fn cache_placement_transform(&mut self, id: u32, transform: [f64; 16]) {
self.placement_transform_cache.insert(id, transform);
}
pub fn cache_size(&self) -> usize {
self.cache.len()
}
}