mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Lazily compute common style affecting attribute info.
This commit is contained in:
parent
51b6568273
commit
a46f0c3b24
2 changed files with 26 additions and 16 deletions
|
@ -7,7 +7,7 @@
|
|||
use rand;
|
||||
use rand::Rng;
|
||||
use std::hash::{Hash, Hasher, SipHasher};
|
||||
use std::slice::Iter;
|
||||
use std::slice::{Iter, IterMut};
|
||||
|
||||
pub struct LRUCache<K, V> {
|
||||
entries: Vec<(K, V)>,
|
||||
|
@ -17,7 +17,7 @@ pub struct LRUCache<K, V> {
|
|||
impl<K: PartialEq, V: Clone> LRUCache<K, V> {
|
||||
pub fn new(size: usize) -> LRUCache<K, V> {
|
||||
LRUCache {
|
||||
entries: vec!(),
|
||||
entries: vec![],
|
||||
cache_size: size,
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,10 @@ impl<K: PartialEq, V: Clone> LRUCache<K, V> {
|
|||
self.entries.iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> IterMut<(K, V)> {
|
||||
self.entries.iter_mut()
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, key: K, val: V) {
|
||||
if self.entries.len() == self.cache_size {
|
||||
self.entries.remove(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue