mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Improve LRU cache behavior in SelectorFlagsMap
This code used to insert duplicate entries to avoid expensive shuffling of the LRU cache. With uluru this is no longer necessary, because reordering the cache is cheap. Now it uses the `LRUCache::find` method from uluru 0.2 to update entries in-place. This should improve the hit rate, because it eliminates unnecessary evictions.
This commit is contained in:
parent
99c2db0549
commit
1f22041f5f
1 changed files with 5 additions and 5 deletions
|
@ -538,17 +538,17 @@ impl<E: TElement> SelectorFlagsMap<E> {
|
|||
pub fn insert_flags(&mut self, element: E, flags: ElementSelectorFlags) {
|
||||
let el = unsafe { SendElement::new(element) };
|
||||
// Check the cache. If the flags have already been noted, we're done.
|
||||
if self.cache.iter().find(|&(_, ref x)| x.0 == el)
|
||||
.map_or(ElementSelectorFlags::empty(), |(_, x)| x.1)
|
||||
.contains(flags) {
|
||||
if let Some(item) = self.cache.find(|x| x.0 == el) {
|
||||
if !item.1.contains(flags) {
|
||||
item.1.insert(flags);
|
||||
self.map.get_mut(&el).unwrap().insert(flags);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let f = self.map.entry(el).or_insert(ElementSelectorFlags::empty());
|
||||
*f |= flags;
|
||||
|
||||
// Insert into the cache. We don't worry about duplicate entries,
|
||||
// which lets us avoid reshuffling.
|
||||
self.cache.insert((unsafe { SendElement::new(element) }, *f))
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue