diff options
author | 2023-04-05 04:10:00 +0200 | |
---|---|---|
committer | 2023-04-05 05:40:44 +0200 | |
commit | f8cd1faa286daaf34cc532bf6d34b932b32eb35a (patch) | |
tree | 9db23ee837803df6954abc65eb5291b6af521083 /tiny_skia/src/text.rs | |
parent | 6270c33ed9823c67f6b6e6dac8fd32521e4ac5a9 (diff) | |
download | iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.tar.gz iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.tar.bz2 iced-f8cd1faa286daaf34cc532bf6d34b932b32eb35a.zip |
Group damage regions by area increase
Diffstat (limited to 'tiny_skia/src/text.rs')
-rw-r--r-- | tiny_skia/src/text.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index 865132b4..512503e0 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -336,6 +336,7 @@ struct Cache { entries: FxHashMap<KeyHash, cosmic_text::Buffer>, recently_used: FxHashSet<KeyHash>, hasher: HashBuilder, + trim_count: usize, } #[cfg(not(target_arch = "wasm32"))] @@ -345,11 +346,14 @@ type HashBuilder = twox_hash::RandomXxHashBuilder64; type HashBuilder = std::hash::BuildHasherDefault<twox_hash::XxHash64>; impl Cache { + const TRIM_INTERVAL: usize = 300; + fn new() -> Self { Self { entries: FxHashMap::default(), recently_used: FxHashSet::default(), hasher: HashBuilder::default(), + trim_count: 0, } } @@ -404,10 +408,16 @@ impl Cache { } fn trim(&mut self) { - self.entries - .retain(|key, _| self.recently_used.contains(key)); + if self.trim_count > Self::TRIM_INTERVAL { + self.entries + .retain(|key, _| self.recently_used.contains(key)); - self.recently_used.clear(); + self.recently_used.clear(); + + self.trim_count = 0; + } else { + self.trim_count += 1; + } } } |