Replace contains() + at() pattern with single find() call to avoid
double lookup overhead. Previously checked map.contains(key) then
used map.at(key), which performs two hash table lookups for the
same operation.
Now uses map.find() and checks the returned iterator against end(),
accessing the value directly from the iterator when found.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
shared_ptr<shard_extent_map_t> ECExtentCache::LRU::find(
const hobject_t &oid, uint64_t offset) {
- Key k(offset, oid);
shared_ptr<shard_extent_map_t> cache = nullptr;
std::lock_guard lock{mutex};
- if (map.contains(k)) {
- auto &&[lru_iter, c] = map.at(k);
+ if (auto found = map.find({offset, oid}); found != map.end()) {
+ auto &&[lru_iter, c] = found->second;
cache = c;
auto it = lru_iter; // Intentional copy.
erase(it, false);