[llvm] [sancov] Avoid repeated map lookups (NFC) (PR #113026)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 18 22:17:02 PDT 2024


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

None

>From 065df3aeac8bc7cc92adb008c82cb9d07712c01a Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 18 Oct 2024 09:31:58 -0700
Subject: [PATCH] [sancov] Avoid repeated map lookups (NFC)

---
 llvm/tools/sancov/sancov.cpp | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/tools/sancov/sancov.cpp b/llvm/tools/sancov/sancov.cpp
index 80f9996ba705ba..b969fc651e0c1c 100644
--- a/llvm/tools/sancov/sancov.cpp
+++ b/llvm/tools/sancov/sancov.cpp
@@ -961,10 +961,9 @@ static FunctionLocs resolveFunctions(const SymbolizedCoverage &Coverage,
         continue;
 
       auto P = std::make_pair(Loc.Line, Loc.Column);
-      auto I = Result.find(Fn);
-      if (I == Result.end() || I->second > P) {
-        Result[Fn] = P;
-      }
+      auto [It, Inserted] = Result.try_emplace(Fn, P);
+      if (!Inserted && It->second > P)
+        It->second = P;
     }
   }
   return Result;



More information about the llvm-commits mailing list