summaryrefslogtreecommitdiffstats
path: root/tiny_skia
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-17 19:58:42 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-03-17 19:58:42 +0100
commitea50ec8df1431c9c6aa8077cd1578c4698dc0314 (patch)
tree5326bf86485925f1f9afaea523d0d4d5742ebe46 /tiny_skia
parentc8f637fc16099c70836574425a6df20a3e2fa801 (diff)
downloadiced-ea50ec8df1431c9c6aa8077cd1578c4698dc0314.tar.gz
iced-ea50ec8df1431c9c6aa8077cd1578c4698dc0314.tar.bz2
iced-ea50ec8df1431c9c6aa8077cd1578c4698dc0314.zip
Trim text `Buffer` cache every frame in `iced_wgpu` and `iced_tiny_skia`
Diffstat (limited to 'tiny_skia')
-rw-r--r--tiny_skia/src/text.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs
index f2935efa..714695b9 100644
--- a/tiny_skia/src/text.rs
+++ b/tiny_skia/src/text.rs
@@ -246,6 +246,8 @@ struct GlyphCache {
}
impl GlyphCache {
+ const TRIM_INTERVAL: usize = 300;
+
fn new() -> Self {
GlyphCache::default()
}
@@ -328,7 +330,7 @@ impl GlyphCache {
}
pub fn trim(&mut self) {
- if self.trim_count > 300 {
+ if self.trim_count > Self::TRIM_INTERVAL {
self.entries
.retain(|key, _| self.recently_used.contains(key));
@@ -345,7 +347,6 @@ struct Cache<'a> {
entries: FxHashMap<KeyHash, cosmic_text::Buffer<'a>>,
recently_used: FxHashSet<KeyHash>,
hasher: HashBuilder,
- trim_count: usize,
}
#[cfg(not(target_arch = "wasm32"))]
@@ -355,14 +356,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,
}
}
@@ -407,16 +405,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();
}
}