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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 6 07:48:43 PDT 2024


Author: Kazu Hirata
Date: 2024-09-06T07:48:39-07:00
New Revision: 01eb071de014759101940096a31d65babc8af04e

URL: https://github.com/llvm/llvm-project/commit/01eb071de014759101940096a31d65babc8af04e
DIFF: https://github.com/llvm/llvm-project/commit/01eb071de014759101940096a31d65babc8af04e.diff

LOG: [mlir] Avoid repeated hash lookups (NFC) (#107519)

Added: 
    

Modified: 
    mlir/lib/IR/AttrTypeSubElements.cpp

Removed: 
    


################################################################################
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