From e0218826a30ace47db88b3602bea5c1d0c6884d5 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 4 Feb 2026 15:08:14 +0800 Subject: [PATCH] erasure-code/isa: eliminate redundant map lookups Use find() instead of count() + operator[] to avoid multiple lookups and reduce nesting. Signed-off-by: Kefu Chai --- .../isa/ErasureCodeIsaTableCache.cc | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/erasure-code/isa/ErasureCodeIsaTableCache.cc b/src/erasure-code/isa/ErasureCodeIsaTableCache.cc index 496f7fdb34d6..c9e6dfebeb24 100644 --- a/src/erasure-code/isa/ErasureCodeIsaTableCache.cc +++ b/src/erasure-code/isa/ErasureCodeIsaTableCache.cc @@ -244,8 +244,6 @@ ErasureCodeIsaTableCache::getDecodingTableFromCache(std::string &signature, dout(12) << "[ get table ] = " << signature << dendl; // we try to fetch a decoding table from an LRU cache - bool found = false; - std::lock_guard lock{codec_tables_guard}; lru_map_t* decode_tbls_map = @@ -254,17 +252,18 @@ ErasureCodeIsaTableCache::getDecodingTableFromCache(std::string &signature, lru_list_t* decode_tbls_lru = getDecodingTablesLru(matrixtype); - if (decode_tbls_map->count(signature)) { - dout(12) << "[ cached table ] = " << signature << dendl; - // copy the table out of the cache - memcpy(table, (*decode_tbls_map)[signature].second.c_str(), k * (m + k)*32); - // find item in LRU queue and push back - dout(12) << "[ cache size ] = " << decode_tbls_lru->size() << dendl; - decode_tbls_lru->splice( (decode_tbls_lru->begin()), *decode_tbls_lru, (*decode_tbls_map)[signature].first); - found = true; + auto lru_map_it = decode_tbls_map->find(signature); + if (lru_map_it == decode_tbls_map->end()) { + return false; } - - return found; + const auto& [lru_list_it, cached_table] = lru_map_it->second; + dout(12) << "[ cached table ] = " << signature << dendl; + // copy the table out of the cache + memcpy(table, cached_table.c_str(), k * (m + k)*32); + // find item in LRU queue and push back + dout(12) << "[ cache size ] = " << decode_tbls_lru->size() << dendl; + decode_tbls_lru->splice( (decode_tbls_lru->begin()), *decode_tbls_lru, lru_list_it); + return true; } // ----------------------------------------------------------------------------- -- 2.47.3