crimson/common: lookup using unordered_map first
authorKefu Chai <kchai@redhat.com>
Sun, 3 Feb 2019 12:32:04 +0000 (20:32 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 19 Feb 2019 06:44:03 +0000 (14:44 +0800)
assuming the unordered_map in LRU cache is faster.

inspired by #25480 by Radoslaw Zarzynski

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/common/shared_lru.h

index 14f2d4e85ef6e8554f482cf510b6b2bac4470da4..25b1fe5e183760991c5daa84a937e28c621d08f7 100644 (file)
@@ -107,6 +107,9 @@ template<class K, class V>
 typename SharedLRU<K,V>::shared_ptr_t
 SharedLRU<K,V>::operator[](const K& key)
 {
+  if (auto found = cache.find(key); found) {
+    return *found;
+  }
   shared_ptr_t val;
   if (auto found = weak_refs.find(key); found != weak_refs.end()) {
     val = found->second.first.lock();
@@ -123,6 +126,9 @@ template<class K, class V>
 typename SharedLRU<K,V>::shared_ptr_t
 SharedLRU<K,V>::find(const K& key)
 {
+  if (auto found = cache.find(key); found) {
+    return *found;
+  }
   shared_ptr_t val;
   if (auto found = weak_refs.find(key); found != weak_refs.end()) {
     val = found->second.first.lock();