[clang] 73683cc - [Basic] Avoid repeated hash lookups (NFC) (#111228)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 5 12:11:05 PDT 2024
Author: Kazu Hirata
Date: 2024-10-05T12:11:01-07:00
New Revision: 73683cc1ab0fe79a4b02b956cf3c033250537bff
URL: https://github.com/llvm/llvm-project/commit/73683cc1ab0fe79a4b02b956cf3c033250537bff
DIFF: https://github.com/llvm/llvm-project/commit/73683cc1ab0fe79a4b02b956cf3c033250537bff.diff
LOG: [Basic] Avoid repeated hash lookups (NFC) (#111228)
Added:
Modified:
clang/lib/Basic/TargetID.cpp
Removed:
################################################################################
diff --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index fa1bfec2aacb9c..b42d1f07013c26 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -92,11 +92,9 @@ parseTargetIDWithFormatCheckingOnly(llvm::StringRef TargetID,
if (Sign != '+' && Sign != '-')
return std::nullopt;
bool IsOn = Sign == '+';
- auto Loc = FeatureMap->find(Feature);
// Each feature can only show up at most once in target ID.
- if (Loc != FeatureMap->end())
+ if (!FeatureMap->try_emplace(Feature, IsOn).second)
return std::nullopt;
- (*FeatureMap)[Feature] = IsOn;
Features = Splits.second;
}
return Processor;
@@ -147,15 +145,15 @@ getConflictTargetIDCombination(const std::set<llvm::StringRef> &TargetIDs) {
struct Info {
llvm::StringRef TargetID;
llvm::StringMap<bool> Features;
+ Info(llvm::StringRef TargetID, const llvm::StringMap<bool> &Features)
+ : TargetID(TargetID), Features(Features) {}
};
llvm::StringMap<Info> FeatureMap;
for (auto &&ID : TargetIDs) {
llvm::StringMap<bool> Features;
llvm::StringRef Proc = *parseTargetIDWithFormatCheckingOnly(ID, &Features);
- auto Loc = FeatureMap.find(Proc);
- if (Loc == FeatureMap.end())
- FeatureMap[Proc] = Info{ID, Features};
- else {
+ auto [Loc, Inserted] = FeatureMap.try_emplace(Proc, ID, Features);
+ if (!Inserted) {
auto &ExistingFeatures = Loc->second.Features;
if (llvm::any_of(Features, [&](auto &F) {
return ExistingFeatures.count(F.first()) == 0;
More information about the cfe-commits
mailing list