diff options
author | Matt Brubeck <mbrubeck@limpet.net> | 2016-05-13 18:13:53 -0700 |
---|---|---|
committer | Matt Brubeck <mbrubeck@limpet.net> | 2016-05-13 18:20:59 -0700 |
commit | dc6be7bba5d2a8a47330b409ee403a4833176118 (patch) | |
tree | 0cf96f3b415fdcd5562798940f7b769d3beeefd3 /components/util/cache.rs | |
parent | d2717c44750ebbecabba90b5dfc6cbca116fc5b4 (diff) | |
download | servo-dc6be7bba5d2a8a47330b409ee403a4833176118.tar.gz servo-dc6be7bba5d2a8a47330b409ee403a4833176118.zip |
Remove unnecessary clone in LRUCache::touch
Diffstat (limited to 'components/util/cache.rs')
-rw-r--r-- | components/util/cache.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/components/util/cache.rs b/components/util/cache.rs index 7af590b015e..f446f43b498 100644 --- a/components/util/cache.rs +++ b/components/util/cache.rs @@ -70,13 +70,13 @@ impl<K: PartialEq, V: Clone> LRUCache<K, V> { } #[inline] - pub fn touch(&mut self, pos: usize) -> V { + pub fn touch(&mut self, pos: usize) -> &V { let last_index = self.entries.len() - 1; if pos != last_index { let entry = self.entries.remove(pos); self.entries.push(entry); } - self.entries[last_index].1.clone() + &self.entries[last_index].1 } pub fn iter(&self) -> Iter<(K, V)> { @@ -92,14 +92,14 @@ impl<K: PartialEq, V: Clone> LRUCache<K, V> { pub fn find(&mut self, key: &K) -> Option<V> { match self.entries.iter().position(|&(ref k, _)| key == k) { - Some(pos) => Some(self.touch(pos)), + Some(pos) => Some(self.touch(pos).clone()), None => None, } } pub fn find_or_create<F>(&mut self, key: K, mut blk: F) -> V where F: FnMut() -> V { match self.entries.iter().position(|&(ref k, _)| *k == key) { - Some(pos) => self.touch(pos), + Some(pos) => self.touch(pos).clone(), None => { let val = blk(); self.insert(key, val.clone()); |