[Mlir-commits] [mlir] [AsmParser] Avoid repeated hash lookups (NFC) (PR #109562)
Kazu Hirata
llvmlistbot at llvm.org
Sat Sep 21 22:41:24 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109562
None
>From 96fd02b2cf50ac11d8487cfb0f250e1d9e5d2d00 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 21 Sep 2024 09:20:32 -0700
Subject: [PATCH] [AsmParser] Avoid repeated hash lookups (NFC)
---
mlir/lib/AsmParser/AsmParserState.cpp | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
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