aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/util/cache.rs
diff options
context:
space:
mode:
authorLars Bergstrom <lars@lars.com>2014-03-14 17:06:40 -0500
committerLars Bergstrom <lars@lars.com>2014-03-18 22:00:48 -0500
commita6100563a6e43471ae43fb155113bc2026992f78 (patch)
tree7e7fbd7976c3da12ff463d6ffbeb1a3a336ae7d3 /src/components/util/cache.rs
parentfe22598c56092880b3e947b4fc9466d1a700e17e (diff)
downloadservo-a6100563a6e43471ae43fb155113bc2026992f78.tar.gz
servo-a6100563a6e43471ae43fb155113bc2026992f78.zip
Rust upgrade for new master rebase
Diffstat (limited to 'src/components/util/cache.rs')
-rw-r--r--src/components/util/cache.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/components/util/cache.rs b/src/components/util/cache.rs
index dc384baf26a..3eb37145df7 100644
--- a/src/components/util/cache.rs
+++ b/src/components/util/cache.rs
@@ -9,6 +9,9 @@ use std::rand;
use std::vec::Items;
use std::vec;
+#[cfg(test)]
+use std::cell::Cell;
+
pub trait Cache<K: Eq, V: Clone> {
fn insert(&mut self, key: K, value: V);
fn find(&mut self, key: &K) -> Option<V>;
@@ -57,8 +60,8 @@ impl<K: Clone + Eq, V: Clone> Cache<K,V> for MonoCache<K,V> {
#[test]
fn test_monocache() {
let mut cache = MonoCache::new(10);
- let one = ~"one";
- let two = ~"two";
+ let one = Cell::new("one");
+ let two = Cell::new("two");
cache.insert(1, one);
assert!(cache.find(&1).is_some());
@@ -104,8 +107,8 @@ impl<K: Clone + Eq + Hash, V: Clone> Cache<K,V> for HashCache<K,V> {
#[test]
fn test_hashcache() {
let mut cache = HashCache::new();
- let one = ~"one";
- let two = ~"two";
+ let one = Cell::new("one");
+ let two = Cell::new("two");
cache.insert(1, one);
assert!(cache.find(&1).is_some());
@@ -244,10 +247,10 @@ impl<K:Clone+Eq+Hash,V:Clone> Cache<K,V> for SimpleHashCache<K,V> {
#[test]
fn test_lru_cache() {
- let one = ~"one";
- let two = ~"two";
- let three = ~"three";
- let four = ~"four";
+ 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::new(2); // (_, _) (cache is empty)