Skip to content

Commit 6ce4426

Browse files
[mlir] Use heterogenous lookups with std::map (NFC) (#115426)
Heterogenous lookups allow us to call find with StringRef, avoiding a temporary heap allocation of std::string.
1 parent 71f82bb commit 6ce4426

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

mlir/include/mlir/IR/DialectRegistry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ bool hasPromisedInterface(Dialect &dialect) {
138138
/// encountered.
139139
class DialectRegistry {
140140
using MapTy =
141-
std::map<std::string, std::pair<TypeID, DialectAllocatorFunction>>;
141+
std::map<std::string, std::pair<TypeID, DialectAllocatorFunction>,
142+
std::less<>>;
142143

143144
public:
144145
explicit DialectRegistry();

mlir/lib/IR/Dialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ DialectRegistry::DialectRegistry() { insert<BuiltinDialect>(); }
217217

218218
DialectAllocatorFunctionRef
219219
DialectRegistry::getDialectAllocator(StringRef name) const {
220-
auto it = registry.find(name.str());
220+
auto it = registry.find(name);
221221
if (it == registry.end())
222222
return nullptr;
223223
return it->second.second;

0 commit comments

Comments
 (0)