[clang] dec641e - [Driver] Avoid repeated hash lookups (NFC) (#111468)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 07:28:16 PDT 2024


Author: Kazu Hirata
Date: 2024-10-08T07:28:12-07:00
New Revision: dec641e473cf416d54766ced34a36be71ecd0037

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

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

Added: 
    

Modified: 
    clang/lib/Driver/MultilibBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/MultilibBuilder.cpp b/clang/lib/Driver/MultilibBuilder.cpp
index 15adf501778093..4b365a164c4586 100644
--- a/clang/lib/Driver/MultilibBuilder.cpp
+++ b/clang/lib/Driver/MultilibBuilder.cpp
@@ -74,13 +74,11 @@ bool MultilibBuilder::isValid() const {
   llvm::StringMap<int> FlagSet;
   for (unsigned I = 0, N = Flags.size(); I != N; ++I) {
     StringRef Flag(Flags[I]);
-    llvm::StringMap<int>::iterator SI = FlagSet.find(Flag.substr(1));
+    auto [SI, Inserted] = FlagSet.try_emplace(Flag.substr(1), I);
 
     assert(StringRef(Flag).front() == '-' || StringRef(Flag).front() == '!');
 
-    if (SI == FlagSet.end())
-      FlagSet[Flag.substr(1)] = I;
-    else if (Flags[I] != Flags[SI->getValue()])
+    if (!Inserted && Flags[I] != Flags[SI->getValue()])
       return false;
   }
   return true;


        


More information about the cfe-commits mailing list