diff options
author | 2024-02-07 14:40:44 +0100 | |
---|---|---|
committer | 2024-02-07 14:40:44 +0100 | |
commit | b4dcf4ecf702a493476791efd95e190e5c1db812 (patch) | |
tree | 5e4c65740122373982e03b529efde17a8c6d99fa /tiny_skia/src | |
parent | bdd1891f434066dcb878520358c2e582f231683a (diff) | |
parent | 9c977116ede9d37429e3c0875a8510e42d976f81 (diff) | |
download | iced-b4dcf4ecf702a493476791efd95e190e5c1db812.tar.gz iced-b4dcf4ecf702a493476791efd95e190e5c1db812.tar.bz2 iced-b4dcf4ecf702a493476791efd95e190e5c1db812.zip |
Merge pull request #2210 from MoSal/glyph_cache_capacity_limit
tiny_skia: Add a capacity limit to `GlyphCache`
Diffstat (limited to 'tiny_skia/src')
-rw-r--r-- | tiny_skia/src/text.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tiny_skia/src/text.rs b/tiny_skia/src/text.rs index c16037cf..8f36f955 100644 --- a/tiny_skia/src/text.rs +++ b/tiny_skia/src/text.rs @@ -273,6 +273,7 @@ struct GlyphCache { impl GlyphCache { const TRIM_INTERVAL: usize = 300; + const CAPACITY_LIMIT: usize = 16 * 1024; fn new() -> Self { GlyphCache::default() @@ -359,12 +360,17 @@ impl GlyphCache { } pub fn trim(&mut self) { - if self.trim_count > Self::TRIM_INTERVAL { + if self.trim_count > Self::TRIM_INTERVAL + || self.recently_used.len() >= Self::CAPACITY_LIMIT + { self.entries .retain(|key, _| self.recently_used.contains(key)); self.recently_used.clear(); + self.entries.shrink_to(Self::CAPACITY_LIMIT); + self.recently_used.shrink_to(Self::CAPACITY_LIMIT); + self.trim_count = 0; } else { self.trim_count += 1; |