From: Samuel Just Date: Tue, 22 Oct 2013 23:17:33 +0000 (-0700) Subject: common/shared_cache.hpp: compact to a single lookup where possible X-Git-Tag: v0.78~231^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ee48c871d62d110d8113d95197fa26105e917582;p=ceph.git common/shared_cache.hpp: compact to a single lookup where possible Signed-off-by: Samuel Just --- diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index 4d5d4f7b8b7f..df52178607d5 100644 --- a/src/common/shared_cache.hpp +++ b/src/common/shared_cache.hpp @@ -44,16 +44,20 @@ class SharedLRU { } void lru_remove(K key) { - if (!contents.count(key)) + typename map >::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 *to_release) { - if (contents.count(key)) { - lru.splice(lru.begin(), lru, contents[key]); + typename map >::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));