[Mlir-commits] [mlir] 59b7461 - [AsmParser] Avoid repeated hash lookups (NFC) (#109562)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Sep 22 00:58:20 PDT 2024
Author: Kazu Hirata
Date: 2024-09-22T00:58:16-07:00
New Revision: 59b7461c139d30ea57db4211decebe43117676fa
URL: https://github.com/llvm/llvm-project/commit/59b7461c139d30ea57db4211decebe43117676fa
DIFF: https://github.com/llvm/llvm-project/commit/59b7461c139d30ea57db4211decebe43117676fa.diff
LOG: [AsmParser] Avoid repeated hash lookups (NFC) (#109562)
Added:
Modified:
mlir/lib/AsmParser/AsmParserState.cpp
Removed:
################################################################################
diff --git a/mlir/lib/AsmParser/AsmParserState.cpp b/mlir/lib/AsmParser/AsmParserState.cpp
index 589bf6aae54d45..9b2b686aee782c 100644
--- a/mlir/lib/AsmParser/AsmParserState.cpp
+++ b/mlir/lib/AsmParser/AsmParserState.cpp
@@ -289,9 +289,9 @@ void AsmParserState::finalizeRegionDefinition() {
}
void AsmParserState::addDefinition(Block *block, SMLoc location) {
- auto it = impl->blocksToIdx.find(block);
- if (it == impl->blocksToIdx.end()) {
- impl->blocksToIdx.try_emplace(block, impl->blocks.size());
+ auto [it, inserted] =
+ impl->blocksToIdx.try_emplace(block, impl->blocks.size());
+ if (inserted) {
impl->blocks.emplace_back(std::make_unique<BlockDefinition>(
block, convertIdLocToRange(location)));
return;
@@ -379,11 +379,10 @@ void AsmParserState::addUses(Value value, ArrayRef<SMLoc> locations) {
}
void AsmParserState::addUses(Block *block, ArrayRef<SMLoc> locations) {
- auto it = impl->blocksToIdx.find(block);
- if (it == impl->blocksToIdx.end()) {
- it = impl->blocksToIdx.try_emplace(block, impl->blocks.size()).first;
+ auto [it, inserted] =
+ impl->blocksToIdx.try_emplace(block, impl->blocks.size());
+ if (inserted)
impl->blocks.emplace_back(std::make_unique<BlockDefinition>(block));
- }
BlockDefinition &def = *impl->blocks[it->second];
for (SMLoc loc : locations)
More information about the Mlir-commits
mailing list