[clang] 0359677 - [Driver] Avoid repeated hash lookups (NFC) (#130888)

via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 08:47:14 PDT 2025


Author: Kazu Hirata
Date: 2025-03-12T08:47:11-07:00
New Revision: 0359677695a741dcf8e26adee692a0dd285fcb91

URL: https://github.com/llvm/llvm-project/commit/0359677695a741dcf8e26adee692a0dd285fcb91
DIFF: https://github.com/llvm/llvm-project/commit/0359677695a741dcf8e26adee692a0dd285fcb91.diff

LOG: [Driver] Avoid repeated hash lookups (NFC) (#130888)

Added: 
    

Modified: 
    clang/lib/Driver/Driver.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9457a19255f21..ba0a7c2180867 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1090,17 +1090,14 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
       std::string NormalizedName = TT.normalize();
 
       // Make sure we don't have a duplicate triple.
-      auto Duplicate = FoundNormalizedTriples.find(NormalizedName);
-      if (Duplicate != FoundNormalizedTriples.end()) {
+      auto [TripleIt, Inserted] =
+          FoundNormalizedTriples.try_emplace(NormalizedName, Val);
+      if (!Inserted) {
         Diag(clang::diag::warn_drv_omp_offload_target_duplicate)
-            << Val << Duplicate->second;
+            << Val << TripleIt->second;
         continue;
       }
 
-      // Store the current triple so that we can check for duplicates in the
-      // following iterations.
-      FoundNormalizedTriples[NormalizedName] = Val;
-
       // If the specified target is invalid, emit a diagnostic.
       if (TT.getArch() == llvm::Triple::UnknownArch) {
         Diag(clang::diag::err_drv_invalid_omp_target) << Val;


        


More information about the cfe-commits mailing list