From ee48c871d62d110d8113d95197fa26105e917582 Mon Sep 17 00:00:00 2001 From: Samuel Just Date: Tue, 22 Oct 2013 16:17:33 -0700 Subject: [PATCH] common/shared_cache.hpp: compact to a single lookup where possible Signed-off-by: Samuel Just --- src/common/shared_cache.hpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/common/shared_cache.hpp b/src/common/shared_cache.hpp index 4d5d4f7b8b7..df52178607d 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));