Trim text Buffer cache every frame in iced_wgpu and iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2023-03-17 19:58:42 +01:00
parent c8f637fc16
commit ea50ec8df1
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 9 additions and 27 deletions

View file

@ -321,7 +321,6 @@ struct Cache<'a> {
entries: FxHashMap<KeyHash, glyphon::Buffer<'a>>,
recently_used: FxHashSet<KeyHash>,
hasher: HashBuilder,
trim_count: usize,
}
#[cfg(not(target_arch = "wasm32"))]
@ -331,14 +330,11 @@ type HashBuilder = twox_hash::RandomXxHashBuilder64;
type HashBuilder = std::hash::BuildHasherDefault<twox_hash::XxHash64>;
impl<'a> Cache<'a> {
const TRIM_INTERVAL: usize = 300;
fn new() -> Self {
Self {
entries: FxHashMap::default(),
recently_used: FxHashSet::default(),
hasher: HashBuilder::default(),
trim_count: 0,
}
}
@ -387,16 +383,10 @@ impl<'a> Cache<'a> {
}
fn trim(&mut self) {
if self.trim_count >= Self::TRIM_INTERVAL {
self.entries
.retain(|key, _| self.recently_used.contains(key));
self.entries
.retain(|key, _| self.recently_used.contains(key));
self.recently_used.clear();
self.trim_count = 0;
} else {
self.trim_count += 1;
}
self.recently_used.clear();
}
}