]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code/isa: eliminate redundant map lookups 67202/head
authorKefu Chai <k.chai@proxmox.com>
Wed, 4 Feb 2026 07:08:14 +0000 (15:08 +0800)
committerKefu Chai <k.chai@proxmox.com>
Mon, 9 Feb 2026 02:34:42 +0000 (10:34 +0800)
Use find() instead of count() + operator[] to avoid multiple lookups
and reduce nesting.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/erasure-code/isa/ErasureCodeIsaTableCache.cc

index 496f7fdb34d644da99afffc14fc17528fe9c06b2..c9e6dfebeb24ca2a45b963641d4025bfa66d4834 100644 (file)
@@ -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;
 }
 
 // -----------------------------------------------------------------------------