Retain text measurements as long as original entries
This commit is contained in:
parent
975eebfc62
commit
00859c25f5
2 changed files with 36 additions and 33 deletions
|
|
@ -388,14 +388,10 @@ impl Cache {
|
|||
) -> (KeyHash, &mut Entry) {
|
||||
let hash = key.hash(self.hasher.build_hasher());
|
||||
|
||||
if let Some(measured_hash) = self.measurements.get(&hash) {
|
||||
let _ = self.recently_used.insert(hash);
|
||||
let _ = self.recently_used.insert(*measured_hash);
|
||||
if let Some(hash) = self.measurements.get(&hash) {
|
||||
let _ = self.recently_used.insert(*hash);
|
||||
|
||||
return (
|
||||
*measured_hash,
|
||||
self.entries.get_mut(measured_hash).unwrap(),
|
||||
);
|
||||
return (*hash, self.entries.get_mut(hash).unwrap());
|
||||
}
|
||||
|
||||
if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) {
|
||||
|
|
@ -421,11 +417,19 @@ impl Cache {
|
|||
|
||||
let _ = entry.insert(Entry { buffer, bounds });
|
||||
|
||||
if key.bounds != bounds {
|
||||
let _ = self.measurements.insert(
|
||||
Key { bounds, ..key }.hash(self.hasher.build_hasher()),
|
||||
hash,
|
||||
);
|
||||
for bounds in [
|
||||
bounds,
|
||||
Size {
|
||||
width: key.bounds.width,
|
||||
..bounds
|
||||
},
|
||||
] {
|
||||
if key.bounds != bounds {
|
||||
let _ = self.measurements.insert(
|
||||
Key { bounds, ..key }.hash(self.hasher.build_hasher()),
|
||||
hash,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -438,10 +442,8 @@ impl Cache {
|
|||
if self.trim_count > Self::TRIM_INTERVAL {
|
||||
self.entries
|
||||
.retain(|key, _| self.recently_used.contains(key));
|
||||
self.measurements.retain(|key, value| {
|
||||
self.recently_used.contains(key)
|
||||
|| self.recently_used.contains(value)
|
||||
});
|
||||
self.measurements
|
||||
.retain(|_, value| self.recently_used.contains(value));
|
||||
|
||||
self.recently_used.clear();
|
||||
|
||||
|
|
|
|||
|
|
@ -385,14 +385,10 @@ impl Cache {
|
|||
) -> (KeyHash, &mut Entry) {
|
||||
let hash = key.hash(self.hasher.build_hasher());
|
||||
|
||||
if let Some(measured_hash) = self.measurements.get(&hash) {
|
||||
let _ = self.recently_used.insert(hash);
|
||||
let _ = self.recently_used.insert(*measured_hash);
|
||||
if let Some(hash) = self.measurements.get(&hash) {
|
||||
let _ = self.recently_used.insert(*hash);
|
||||
|
||||
return (
|
||||
*measured_hash,
|
||||
self.entries.get_mut(measured_hash).unwrap(),
|
||||
);
|
||||
return (*hash, self.entries.get_mut(hash).unwrap());
|
||||
}
|
||||
|
||||
if let hash_map::Entry::Vacant(entry) = self.entries.entry(hash) {
|
||||
|
|
@ -415,14 +411,21 @@ impl Cache {
|
|||
);
|
||||
|
||||
let bounds = measure(&buffer);
|
||||
|
||||
let _ = entry.insert(Entry { buffer, bounds });
|
||||
|
||||
if key.bounds != bounds {
|
||||
let _ = self.measurements.insert(
|
||||
Key { bounds, ..key }.hash(self.hasher.build_hasher()),
|
||||
hash,
|
||||
);
|
||||
for bounds in [
|
||||
bounds,
|
||||
Size {
|
||||
width: key.bounds.width,
|
||||
..bounds
|
||||
},
|
||||
] {
|
||||
if key.bounds != bounds {
|
||||
let _ = self.measurements.insert(
|
||||
Key { bounds, ..key }.hash(self.hasher.build_hasher()),
|
||||
hash,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,10 +437,8 @@ impl Cache {
|
|||
fn trim(&mut self) {
|
||||
self.entries
|
||||
.retain(|key, _| self.recently_used.contains(key));
|
||||
self.measurements.retain(|key, value| {
|
||||
self.recently_used.contains(key)
|
||||
|| self.recently_used.contains(value)
|
||||
});
|
||||
self.measurements
|
||||
.retain(|_, value| self.recently_used.contains(value));
|
||||
|
||||
self.recently_used.clear();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue