[Mlir-commits] [mlir] [AsmParser] Avoid repeated hash lookups (NFC) (PR #109562)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Sep 21 22:41:57 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) mlir/lib/AsmParser/AsmParserState.cpp (+6-7) 


``````````diff
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)

``````````

</details>


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


More information about the Mlir-commits mailing list