[Mlir-commits] [mlir] [mlir] Use heterogenous lookups with std::map (NFC) (PR #115426)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Nov 7 22:32:58 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


---
Full diff: https://github.com/llvm/llvm-project/pull/115426.diff


2 Files Affected:

- (modified) mlir/include/mlir/IR/DialectRegistry.h (+2-1) 
- (modified) mlir/lib/IR/Dialect.cpp (+1-1) 


``````````diff
diff --git a/mlir/include/mlir/IR/DialectRegistry.h b/mlir/include/mlir/IR/DialectRegistry.h
index 2c1f6964998e83..d3d53488fe72df 100644
--- a/mlir/include/mlir/IR/DialectRegistry.h
+++ b/mlir/include/mlir/IR/DialectRegistry.h
@@ -138,7 +138,8 @@ bool hasPromisedInterface(Dialect &dialect) {
 /// encountered.
 class DialectRegistry {
   using MapTy =
-      std::map<std::string, std::pair<TypeID, DialectAllocatorFunction>>;
+      std::map<std::string, std::pair<TypeID, DialectAllocatorFunction>,
+               std::less<>>;
 
 public:
   explicit DialectRegistry();
diff --git a/mlir/lib/IR/Dialect.cpp b/mlir/lib/IR/Dialect.cpp
index cc80677a4078f8..47568594947cfc 100644
--- a/mlir/lib/IR/Dialect.cpp
+++ b/mlir/lib/IR/Dialect.cpp
@@ -217,7 +217,7 @@ DialectRegistry::DialectRegistry() { insert<BuiltinDialect>(); }
 
 DialectAllocatorFunctionRef
 DialectRegistry::getDialectAllocator(StringRef name) const {
-  auto it = registry.find(name.str());
+  auto it = registry.find(name);
   if (it == registry.end())
     return nullptr;
   return it->second.second;

``````````

</details>


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


More information about the Mlir-commits mailing list