From: Kefu Chai Date: Sun, 3 Feb 2019 12:32:04 +0000 (+0800) Subject: crimson/common: lookup using unordered_map first X-Git-Tag: v14.1.0~66^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a408f7e2e5a94c709e5d6e1955295aeef586139d;p=ceph.git crimson/common: lookup using unordered_map first assuming the unordered_map in LRU cache is faster. inspired by #25480 by Radoslaw Zarzynski Signed-off-by: Kefu Chai --- diff --git a/src/crimson/common/shared_lru.h b/src/crimson/common/shared_lru.h index 14f2d4e85ef6..25b1fe5e1837 100644 --- a/src/crimson/common/shared_lru.h +++ b/src/crimson/common/shared_lru.h @@ -107,6 +107,9 @@ template typename SharedLRU::shared_ptr_t SharedLRU::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 typename SharedLRU::shared_ptr_t SharedLRU::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();