Skip to content


Improve LRU cache behavior in SelectorFlagsMap
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mbrubeck committed Dec 7, 2017
1 parent 99c2db0 commit 1f22041
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions components/style/
Expand Up @@ -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) {

let f =;
*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))

Expand Down

0 comments on commit 1f22041

Please sign in to comment.