mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Iterate the LRU cache contents from back to front.
We put the more recently used item last, so iterating then from left to right is pointless.
This commit is contained in:
parent
2f8cf6afc3
commit
d3e7f1f0f4
2 changed files with 15 additions and 9 deletions
|
@ -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<K> {
|
|||
cache_size: usize,
|
||||
}
|
||||
|
||||
/// A iterator over the items of the LRU cache.
|
||||
pub type LRUCacheIterator<'a, K> = iter::Rev<slice::Iter<'a, K>>;
|
||||
|
||||
/// A iterator over the mutable items of the LRU cache.
|
||||
pub type LRUCacheMutIterator<'a, K> = iter::Rev<slice::IterMut<'a, K>>;
|
||||
|
||||
impl<K: PartialEq> LRUCache<K> {
|
||||
/// Create a new LRU cache with `size` elements at most.
|
||||
pub fn new(size: usize) -> Self {
|
||||
|
@ -35,14 +41,15 @@ impl<K: PartialEq> LRUCache<K> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Iterate over the contents of this cache.
|
||||
pub fn iter(&self) -> Iter<K> {
|
||||
self.entries.iter()
|
||||
/// Iterate over the contents of this cache, from more to less recently
|
||||
/// used.
|
||||
pub fn iter(&self) -> LRUCacheIterator<K> {
|
||||
self.entries.iter().rev()
|
||||
}
|
||||
|
||||
/// Iterate mutably over the contents of this cache.
|
||||
pub fn iter_mut(&mut self) -> IterMut<K> {
|
||||
self.entries.iter_mut()
|
||||
pub fn iter_mut(&mut self) -> LRUCacheMutIterator<K> {
|
||||
self.entries.iter_mut().rev()
|
||||
}
|
||||
|
||||
/// Insert a given key in the cache.
|
||||
|
|
|
@ -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<E: TElement> StyleSharingCandidateCache<E> {
|
|||
}
|
||||
}
|
||||
|
||||
fn iter_mut(&mut self) -> IterMut<StyleSharingCandidate<E>> {
|
||||
fn iter_mut(&mut self) -> LRUCacheMutIterator<StyleSharingCandidate<E>> {
|
||||
self.cache.iter_mut()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue