[Mlir-commits] [mlir] [mlir] Use heterogenous lookups with std::map (NFC) (PR #115426)
Kazu Hirata
llvmlistbot at llvm.org
Thu Nov 7 22:32:26 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/115426
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
>From abcfffdfe851d6606650e1c779ba77dbbeff257b Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Thu, 7 Nov 2024 21:16:37 -0800
Subject: [PATCH] [mlir] Use heterogenous lookups with std::map (NFC)
Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
mlir/include/mlir/IR/DialectRegistry.h | 3 ++-
mlir/lib/IR/Dialect.cpp | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
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;
More information about the Mlir-commits
mailing list