summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tiny_skia/src/text.rs20
-rw-r--r--wgpu/src/text.rs16
2 files changed, 9 insertions, 27 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();
}
}
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs
index e99844e6..35f24cd9 100644
--- a/wgpu/src/text.rs
+++ b/wgpu/src/text.rs
@@ -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.recently_used.clear();
+ self.entries
+ .retain(|key, _| self.recently_used.contains(key));
- self.trim_count = 0;
- } else {
- self.trim_count += 1;
- }
+ self.recently_used.clear();
}
}