Skip to content
Browse files

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.
  • Loading branch information
mbrubeck committed Dec 7, 2017
1 parent 99c2db0 commit 1f22041f5f980446e102c2a709404999ad57aee8
Showing with 5 additions and 5 deletions.
  1. +5 −5 components/style/
@@ -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))

0 comments on commit 1f22041

Please sign in to comment.
You can’t perform that action at this time.