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

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 7 19:45:47 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/111468.diff


1 Files Affected:

- (modified) clang/lib/Driver/MultilibBuilder.cpp (+2-4) 


``````````diff
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/111468


More information about the cfe-commits mailing list