From 5bd93181f349f7160b694d7b1a594bfe7263d063 Mon Sep 17 00:00:00 2001 From: Mohammad AlSaleh Date: Mon, 22 Jan 2024 11:27:29 +0300 Subject: tiny_skia: Add a capacity limit to `GlyphCache` * Trim the cache if `recently_used` size reaches the limit, even if a trim interval hasn't passed. * Shrink `entries` and `recently_used` to the limit when trimming. Signed-off-by: Mohammad AlSaleh --- tiny_skia/src/text.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; -- cgit From 9c977116ede9d37429e3c0875a8510e42d976f81 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 7 Feb 2024 14:28:20 +0100 Subject: Update `CHANGELOG` --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03535ccd..7b4d5cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,6 +58,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use `Radians` for angle fields in `Arc` and `arc::Elliptical`. [#2027](https://github.com/iced-rs/iced/pull/2027) - Assert dimensions of quads are normal in `iced_tiny_skia`. [#2082](https://github.com/iced-rs/iced/pull/2082) - Remove `position` from `overlay::Element`. [#2226](https://github.com/iced-rs/iced/pull/2226) +- Add a capacity limit to the `GlyphCache` in `iced_tiny_skia`. [#2210](https://github.com/iced-rs/iced/pull/2210) ### Fixed - Clipping of `TextInput` selection. [#2199](https://github.com/iced-rs/iced/pull/2199) @@ -126,6 +127,7 @@ Many thanks to... - @lufte - @matze - @MichalLebeda +- @MoSal - @MrAntix - @nicksenger - @Nisatru -- cgit