[clang] [Driver] Avoid repeated hash lookups (NFC) (PR #130888)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 21:26:00 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-driver
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/130888.diff
1 Files Affected:
- (modified) clang/lib/Driver/Driver.cpp (+4-7)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/130888
More information about the cfe-commits
mailing list