[Mlir-commits] [mlir] [Affine] Avoid repeated hash lookups (NFC) (PR #111330)

Nikita Popov llvmlistbot at llvm.org
Mon Oct 7 00:40:42 PDT 2024


================
@@ -1927,9 +1927,9 @@ static std::optional<int64_t> getMemoryFootprintBytes(Block &block,
       return opInst->emitError("error obtaining memory region\n");
     }
 
-    auto it = regions.find(region->memref);
-    if (it == regions.end()) {
-      regions[region->memref] = std::move(region);
+    auto [it, inserted] = regions.try_emplace(region->memref);
+    if (inserted) {
+      it->second = std::move(region);
----------------
nikic wrote:

Technically you could also do the std::move in try_emplace (because it will only actually get moved if inserted), but it's probably more confusing than this variant...

https://github.com/llvm/llvm-project/pull/111330


More information about the Mlir-commits mailing list