]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/shared_cache.hpp: compact to a single lookup where possible
authorSamuel Just <sam.just@inktank.com>
Tue, 22 Oct 2013 23:17:33 +0000 (16:17 -0700)
committerGreg Farnum <greg@inktank.com>
Fri, 31 Jan 2014 23:54:40 +0000 (15:54 -0800)
Signed-off-by: Samuel Just <sam.just@inktank.com>
src/common/shared_cache.hpp

index 4d5d4f7b8b7f40c3643ecbf568916bf0fc60e790..df52178607d519500e0b2bf585b6a0bb60b1e9a2 100644 (file)
@@ -44,16 +44,20 @@ class SharedLRU {
   }
 
   void lru_remove(K key) {
-    if (!contents.count(key))
+    typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
+      contents.find(key);
+    if (i == contents.end())
       return;
-    lru.erase(contents[key]);
+    lru.erase(i->second);
     --size;
-    contents.erase(key);
+    contents.erase(i);
   }
 
   void lru_add(K key, VPtr val, list<VPtr> *to_release) {
-    if (contents.count(key)) {
-      lru.splice(lru.begin(), lru, contents[key]);
+    typename map<K, typename list<pair<K, VPtr> >::iterator>::iterator i =
+      contents.find(key);
+    if (i != contents.end()) {
+      lru.splice(lru.begin(), lru, i->second);
     } else {
       ++size;
       lru.push_front(make_pair(key, val));