From 73dca5e323756ad29003517587c4092e8b6a246d Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 28 Jun 2023 00:44:23 +0200 Subject: Reuse entries in `text::Cache` in `iced_tiny_skia` --- wgpu/src/text.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'wgpu/src/text.rs') diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 04943049..e0484239 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -348,7 +348,7 @@ fn to_shaping(shaping: Shaping) -> glyphon::Shaping { struct Cache { entries: FxHashMap, - bound_entries: FxHashMap, + measurements: FxHashMap, recently_used: FxHashSet, hasher: HashBuilder, } @@ -368,7 +368,7 @@ impl Cache { fn new() -> Self { Self { entries: FxHashMap::default(), - bound_entries: FxHashMap::default(), + measurements: FxHashMap::default(), recently_used: FxHashSet::default(), hasher: HashBuilder::default(), } @@ -385,11 +385,14 @@ impl Cache { ) -> (KeyHash, &mut Entry) { let hash = key.hash(self.hasher.build_hasher()); - if let Some(bound_hash) = self.bound_entries.get(&hash) { + if let Some(measured_hash) = self.measurements.get(&hash) { let _ = self.recently_used.insert(hash); - let _ = self.recently_used.insert(*bound_hash); + let _ = self.recently_used.insert(*measured_hash); - return (*bound_hash, self.entries.get_mut(&bound_hash).unwrap()); + return ( + *measured_hash, + self.entries.get_mut(&measured_hash).unwrap(), + ); } if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) { @@ -416,7 +419,7 @@ impl Cache { let _ = entry.insert(Entry { buffer, bounds }); if key.bounds != bounds { - let _ = self.bound_entries.insert( + let _ = self.measurements.insert( Key { bounds, ..key }.hash(self.hasher.build_hasher()), hash, ); @@ -431,7 +434,7 @@ impl Cache { fn trim(&mut self) { self.entries .retain(|key, _| self.recently_used.contains(key)); - self.bound_entries + self.measurements .retain(|key, _| self.recently_used.contains(key)); self.recently_used.clear(); -- cgit