[llvm] [Passes] Avoid repeated hash lookups (NFC) (PR #110790)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 21:25:43 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/110790

None

>From 9a5c15cb7a870cd859dd5870c63cc5947717c4ef Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 1 Oct 2024 07:52:06 -0700
Subject: [PATCH] [Passes] Avoid repeated hash lookups (NFC)

---
 llvm/lib/Passes/StandardInstrumentations.cpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 036484c9c1c0c4..18a62c61cdb135 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -2039,13 +2039,14 @@ DotCfgDiff::DotCfgDiff(StringRef Title, const FuncDataT<DCData> &Before,
     StringRef Colour = E.second;
 
     // Look for an edge from Source to Sink
-    if (EdgeLabels.count(SourceSink) == 0)
-      EdgeLabels.insert({SourceSink, colourize(Value.str(), Colour)});
+    auto [It, Inserted] = EdgeLabels.try_emplace(SourceSink);
+    if (Inserted)
+      It->getValue() = colourize(Value.str(), Colour);
     else {
-      StringRef V = EdgeLabels.find(SourceSink)->getValue();
+      StringRef V = It->getValue();
       std::string NV = colourize(V.str() + " " + Value.str(), Colour);
       Colour = CommonColour;
-      EdgeLabels[SourceSink] = NV;
+      It->getValue() = NV;
     }
     SourceNode.addEdge(SinkNode, Value, Colour);
   }



More information about the llvm-commits mailing list