common/shared_cache.hpp: compact to a single lookup where possible

Signed-off-by: Samuel Just <sam.just@inktank.com>
This commit is contained in:
Samuel Just 2013-10-22 16:17:33 -07:00 committed by Greg Farnum
parent 27b5f2b873
commit ee48c871d6

View 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));