diff options
Diffstat (limited to '')
| -rw-r--r-- | tiny_skia/src/text.rs | 20 | 
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();      }  } | 
