[llvm] [llvm-diff] Avoid repeated hash lookups (NFC) (PR #113025)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 22:16:14 PDT 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/113025
None
>From e8a329bda9965d31795067f165e126ac222365de Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 18 Oct 2024 09:25:46 -0700
Subject: [PATCH] [llvm-diff] Avoid repeated hash lookups (NFC)
---
llvm/tools/llvm-diff/lib/DifferenceEngine.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
index 05cae4b67d7e52..9be0eec7b73f3e 100644
--- a/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
+++ b/llvm/tools/llvm-diff/lib/DifferenceEngine.cpp
@@ -189,11 +189,11 @@ class FunctionDifferenceEngine {
// The returned reference is not permanently valid and should not be stored.
BlockDiffCandidate &getOrCreateBlockDiffCandidate(const BasicBlock *LBB,
const BasicBlock *RBB) {
- auto It = BlockDiffCandidateIndices.find(LBB);
+ auto [It, Inserted] =
+ BlockDiffCandidateIndices.try_emplace(LBB, BlockDiffCandidates.size());
// Check if LBB already has a diff candidate
- if (It == BlockDiffCandidateIndices.end()) {
+ if (Inserted) {
// Add new one
- BlockDiffCandidateIndices[LBB] = BlockDiffCandidates.size();
BlockDiffCandidates.push_back(
{LBB, RBB, SmallDenseMap<const Value *, const Value *>(), false});
return BlockDiffCandidates.back();
More information about the llvm-commits
mailing list