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

Kazu Hirata llvmlistbot at llvm.org
Thu Sep 5 21:37:18 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/107519

None

>From edb03f23169c5f81462ac7b606f117022935401f Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 5 Sep 2024 21:32:18 -0700
Subject: [PATCH] [mlir] Avoid repeated hash lookups (NFC)

---
 mlir/lib/IR/AttrTypeSubElements.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/mlir/lib/IR/AttrTypeSubElements.cpp b/mlir/lib/IR/AttrTypeSubElements.cpp
index 783236ed3a9df6..863e1aa95f2fb7 100644
--- a/mlir/lib/IR/AttrTypeSubElements.cpp
+++ b/mlir/lib/IR/AttrTypeSubElements.cpp
@@ -27,10 +27,10 @@ WalkResult AttrTypeWalker::walkImpl(T element, WalkFns &walkFns,
                                     WalkOrder order) {
   // Check if we've already walk this element before.
   auto key = std::make_pair(element.getAsOpaquePointer(), (int)order);
-  auto it = visitedAttrTypes.find(key);
-  if (it != visitedAttrTypes.end())
+  auto [it, inserted] =
+      visitedAttrTypes.try_emplace(key, WalkResult::advance());
+  if (!inserted)
     return it->second;
-  visitedAttrTypes.try_emplace(key, WalkResult::advance());
 
   // If we are walking in post order, walk the sub elements first.
   if (order == WalkOrder::PostOrder) {



More information about the Mlir-commits mailing list