mirror of
https://github.com/servo/servo.git
synced 2025-08-08 23:15:33 +01:00
Auto merge of #15888 - emilio:caching, r=Ms2ger
style: Simplify style sharing code. No functional changes, just some code cleanup. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15888) <!-- Reviewable:end -->
This commit is contained in:
commit
5c46e86546
4 changed files with 17 additions and 80 deletions
|
@ -1,40 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::Cell;
|
||||
use style::cache::LRUCache;
|
||||
|
||||
#[test]
|
||||
fn test_lru_cache() {
|
||||
let one = Cell::new("one");
|
||||
let two = Cell::new("two");
|
||||
let three = Cell::new("three");
|
||||
let four = Cell::new("four");
|
||||
|
||||
// Test normal insertion.
|
||||
let mut cache: LRUCache<usize, Cell<&str>> = LRUCache::new(2); // (_, _) (cache is empty)
|
||||
cache.insert(1, one); // (1, _)
|
||||
cache.insert(2, two); // (1, 2)
|
||||
cache.insert(3, three); // (2, 3)
|
||||
|
||||
assert!(cache.find(&1).is_none()); // (2, 3) (no change)
|
||||
assert!(cache.find(&3).is_some()); // (2, 3)
|
||||
assert!(cache.find(&2).is_some()); // (3, 2)
|
||||
|
||||
// Test that LRU works (this insertion should replace 3, not 2).
|
||||
cache.insert(4, four); // (2, 4)
|
||||
|
||||
assert!(cache.find(&1).is_none()); // (2, 4) (no change)
|
||||
assert!(cache.find(&2).is_some()); // (4, 2)
|
||||
assert!(cache.find(&3).is_none()); // (4, 2) (no change)
|
||||
assert!(cache.find(&4).is_some()); // (2, 4) (no change)
|
||||
|
||||
// Test find_or_create.
|
||||
cache.find_or_create(1, || { Cell::new("one") }); // (4, 1)
|
||||
|
||||
assert!(cache.find(&1).is_some()); // (4, 1) (no change)
|
||||
assert!(cache.find(&2).is_none()); // (4, 1) (no change)
|
||||
assert!(cache.find(&3).is_none()); // (4, 1) (no change)
|
||||
assert!(cache.find(&4).is_some()); // (1, 4)
|
||||
}
|
|
@ -23,7 +23,6 @@ extern crate test;
|
|||
|
||||
mod animated_properties;
|
||||
mod attr;
|
||||
mod cache;
|
||||
mod keyframes;
|
||||
mod logical_geometry;
|
||||
mod media_queries;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue