diff --git a/components/style/cache.rs b/components/style/cache.rs index 313f3ea193c..a2432ee9fa7 100644 --- a/components/style/cache.rs +++ b/components/style/cache.rs @@ -6,7 +6,7 @@ #![deny(missing_docs)] -use std::slice::{Iter, IterMut}; +use std::{iter, slice}; /// A LRU cache used to store a set of at most `n` elements at the same time. /// @@ -16,6 +16,12 @@ pub struct LRUCache { cache_size: usize, } +/// A iterator over the items of the LRU cache. +pub type LRUCacheIterator<'a, K> = iter::Rev>; + +/// A iterator over the mutable items of the LRU cache. +pub type LRUCacheMutIterator<'a, K> = iter::Rev>; + impl LRUCache { /// Create a new LRU cache with `size` elements at most. pub fn new(size: usize) -> Self { @@ -35,14 +41,15 @@ impl LRUCache { } } - /// Iterate over the contents of this cache. - pub fn iter(&self) -> Iter { - self.entries.iter() + /// Iterate over the contents of this cache, from more to less recently + /// used. + pub fn iter(&self) -> LRUCacheIterator { + self.entries.iter().rev() } /// Iterate mutably over the contents of this cache. - pub fn iter_mut(&mut self) -> IterMut { - self.entries.iter_mut() + pub fn iter_mut(&mut self) -> LRUCacheMutIterator { + self.entries.iter_mut().rev() } /// Insert a given key in the cache. diff --git a/components/style/matching.rs b/components/style/matching.rs index b8d6d567338..aae30ce1948 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -10,7 +10,7 @@ use {Atom, LocalName}; use animation::{self, Animation, PropertyAnimation}; use atomic_refcell::AtomicRefMut; -use cache::LRUCache; +use cache::{LRUCache, LRUCacheMutIterator}; use cascade_info::CascadeInfo; use context::{SequentialTask, SharedStyleContext, StyleContext}; use data::{ComputedStyle, ElementData, ElementStyles, RestyleData}; @@ -27,7 +27,6 @@ use selectors::matching::AFFECTED_BY_PSEUDO_ELEMENTS; use servo_config::opts; use sink::ForgetfulSink; use std::collections::hash_map::Entry; -use std::slice::IterMut; use std::sync::Arc; use stylist::ApplicableDeclarationBlock; @@ -366,7 +365,7 @@ impl StyleSharingCandidateCache { } } - fn iter_mut(&mut self) -> IterMut> { + fn iter_mut(&mut self) -> LRUCacheMutIterator> { self.cache.iter_mut() }