[Mlir-commits] [mlir] 56b2907 - [mlir] Avoid repeated hash lookups (NFC) (#107518)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Sep 6 07:41:54 PDT 2024


Author: Kazu Hirata
Date: 2024-09-06T07:41:52-07:00
New Revision: 56b29074fe924243640547a9fec35bef0942b210

URL: https://github.com/llvm/llvm-project/commit/56b29074fe924243640547a9fec35bef0942b210
DIFF: https://github.com/llvm/llvm-project/commit/56b29074fe924243640547a9fec35bef0942b210.diff

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

Added: 
    

Modified: 
    mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
index 128eacdbe6ab7a..494026d78af3fd 100644
--- a/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
+++ b/mlir/include/mlir/Dialect/Transform/IR/TransformDialect.h
@@ -298,13 +298,10 @@ void TransformDialect::addTypeIfNotRegistered() {
 template <typename DataTy>
 DataTy &TransformDialect::getOrCreateExtraData() {
   TypeID typeID = TypeID::get<DataTy>();
-  auto it = extraData.find(typeID);
-  if (it != extraData.end())
-    return static_cast<DataTy &>(*it->getSecond());
-
-  auto emplaced =
-      extraData.try_emplace(typeID, std::make_unique<DataTy>(getContext()));
-  return static_cast<DataTy &>(*emplaced.first->getSecond());
+  auto [it, inserted] = extraData.try_emplace(typeID);
+  if (inserted)
+    it->getSecond() = std::make_unique<DataTy>(getContext());
+  return static_cast<DataTy &>(*it->getSecond());
 }
 
 /// A wrapper for transform dialect extensions that forces them to be


        


More information about the Mlir-commits mailing list