[lld] [lld][WebAssembly] Use `.contains` rather than `.count` for testing set membership. NFC (PR #176610)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 17 15:17:34 PST 2026
https://github.com/sbc100 created https://github.com/llvm/llvm-project/pull/176610
I guess this method didn't exist back when this code was first written?
>From e56bcd06a21d1fd79c2e3c799842baeacccf52bb Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Sat, 17 Jan 2026 15:14:08 -0800
Subject: [PATCH] [lld][WebAssembly] Use `.contains` rather than `.count` for
testing set membership. NFC
I guess this method didn't exist back when this code was first written?
---
lld/wasm/Driver.cpp | 2 +-
lld/wasm/Relocations.cpp | 2 +-
lld/wasm/SymbolTable.cpp | 2 +-
lld/wasm/SyntheticSections.h | 6 +++---
lld/wasm/Writer.cpp | 22 +++++++++++-----------
5 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index d18126bef766f..87ccac2215b47 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -1394,7 +1394,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
if (!ctx.arg.relocatable && !ctx.arg.shared &&
!ctx.sym.callCtors->isUsedInRegularObj &&
ctx.sym.callCtors->getName() != ctx.arg.entry &&
- !ctx.arg.exportedSymbols.count(ctx.sym.callCtors->getName())) {
+ !ctx.arg.exportedSymbols.contains(ctx.sym.callCtors->getName())) {
if (Symbol *callDtors =
handleUndefined("__wasm_call_dtors", "<internal>")) {
if (auto *callDtorsFunc = dyn_cast<DefinedFunction>(callDtors)) {
diff --git a/lld/wasm/Relocations.cpp b/lld/wasm/Relocations.cpp
index 52888ad25034e..a3f87ea3d69c0 100644
--- a/lld/wasm/Relocations.cpp
+++ b/lld/wasm/Relocations.cpp
@@ -41,7 +41,7 @@ static bool allowUndefined(const Symbol* sym) {
if (isa<UndefinedFunction>(sym) && ctx.arg.importUndefined)
return true;
- return ctx.arg.allowUndefinedSymbols.count(sym->getName()) != 0;
+ return ctx.arg.allowUndefinedSymbols.contains(sym->getName());
}
static void reportUndefined(ObjFile *file, Symbol *sym) {
diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp
index 91677b34ea2ca..5c811e0ff42a7 100644
--- a/lld/wasm/SymbolTable.cpp
+++ b/lld/wasm/SymbolTable.cpp
@@ -235,7 +235,7 @@ DefinedFunction *SymbolTable::addSyntheticFunction(StringRef name,
DefinedData *SymbolTable::addOptionalDataSymbol(StringRef name,
uint64_t value) {
Symbol *s = find(name);
- if (!s && (ctx.arg.exportAll || ctx.arg.exportedSymbols.count(name) != 0))
+ if (!s && (ctx.arg.exportAll || ctx.arg.exportedSymbols.contains(name)))
s = insertName(name).first;
else if (!s || s->isDefined())
return nullptr;
diff --git a/lld/wasm/SyntheticSections.h b/lld/wasm/SyntheticSections.h
index 068fbed11f4a7..313cbd63ecbf2 100644
--- a/lld/wasm/SyntheticSections.h
+++ b/lld/wasm/SyntheticSections.h
@@ -373,7 +373,7 @@ class NameSection : public SyntheticSection {
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "name"),
segments(segments) {}
bool isNeeded() const override {
- if (ctx.arg.stripAll && !ctx.arg.keepSections.count(name))
+ if (ctx.arg.stripAll && !ctx.arg.keepSections.contains(name))
return false;
return numNames() > 0;
}
@@ -396,7 +396,7 @@ class ProducersSection : public SyntheticSection {
ProducersSection()
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "producers") {}
bool isNeeded() const override {
- if (ctx.arg.stripAll && !ctx.arg.keepSections.count(name))
+ if (ctx.arg.stripAll && !ctx.arg.keepSections.contains(name))
return false;
return fieldCount() > 0;
}
@@ -417,7 +417,7 @@ class TargetFeaturesSection : public SyntheticSection {
TargetFeaturesSection()
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, "target_features") {}
bool isNeeded() const override {
- if (ctx.arg.stripAll && !ctx.arg.keepSections.count(name))
+ if (ctx.arg.stripAll && !ctx.arg.keepSections.contains(name))
return false;
return features.size() > 0;
}
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 9a5b56fc52e2f..ace5e68960600 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -628,20 +628,20 @@ void Writer::populateTargetFeatures() {
goto done;
if (ctx.arg.sharedMemory) {
- if (disallowed.count("shared-mem"))
+ if (disallowed.contains("shared-mem"))
error("--shared-memory is disallowed by " + disallowed["shared-mem"] +
" because it was not compiled with 'atomics' or 'bulk-memory' "
"features.");
for (auto feature : {"atomics", "bulk-memory"})
- if (!allowed.count(feature))
+ if (!allowed.contains(feature))
error(StringRef("'") + feature +
"' feature must be used in order to use shared memory");
}
if (tlsUsed) {
for (auto feature : {"atomics", "bulk-memory"})
- if (!allowed.count(feature))
+ if (!allowed.contains(feature))
error(StringRef("'") + feature +
"' feature must be used in order to use thread-local storage");
}
@@ -649,7 +649,7 @@ void Writer::populateTargetFeatures() {
// Validate that used features are allowed in output
if (!inferFeatures) {
for (const auto &feature : used.keys()) {
- if (!allowed.count(std::string(feature)))
+ if (!allowed.contains(std::string(feature)))
error(Twine("Target feature '") + feature + "' used by " +
used[feature] + " is not allowed.");
}
@@ -663,7 +663,7 @@ void Writer::populateTargetFeatures() {
if (feature.Prefix == WASM_FEATURE_PREFIX_DISALLOWED)
continue;
objectFeatures.insert(feature.Name);
- if (disallowed.count(feature.Name))
+ if (disallowed.contains(feature.Name))
error(Twine("Target feature '") + feature.Name + "' used in " +
fileName + " is disallowed by " + disallowed[feature.Name] +
". Use --no-check-features to suppress.");
@@ -678,10 +678,10 @@ void Writer::populateTargetFeatures() {
// Finally, if we are emitting relocations, they may refer to locations within
// the bss segments, so these segments need to exist in the binary.
if (ctx.arg.emitRelocs ||
- (ctx.arg.memoryImport.has_value() && !allowed.count("bulk-memory")))
+ (ctx.arg.memoryImport.has_value() && !allowed.contains("bulk-memory")))
ctx.emitBssSegments = true;
- if (allowed.count("extended-const"))
+ if (allowed.contains("extended-const"))
ctx.arg.extendedConst = true;
for (auto &feature : allowed)
@@ -692,7 +692,7 @@ void Writer::checkImportExportTargetFeatures() {
if (ctx.arg.relocatable || !ctx.arg.checkFeatures)
return;
- if (out.targetFeaturesSec->features.count("mutable-globals") == 0) {
+ if (!out.targetFeaturesSec->features.contains("mutable-globals")) {
for (const Symbol *sym : out.importSec->importedSymbols) {
if (auto *global = dyn_cast<GlobalSymbol>(sym)) {
if (global->getGlobalType()->Mutable) {
@@ -748,7 +748,7 @@ static bool shouldImport(Symbol *sym) {
if (ctx.isPic || ctx.arg.relocatable || ctx.arg.importUndefined ||
ctx.arg.unresolvedSymbols == UnresolvedPolicy::ImportDynamic)
return true;
- if (ctx.arg.allowUndefinedSymbols.count(sym->getName()) != 0)
+ if (ctx.arg.allowUndefinedSymbols.contains(sym->getName()))
return true;
return sym->isImported();
@@ -785,7 +785,7 @@ void Writer::calculateExports() {
out.importSec->getNumImportedGlobals() + out.globalSec->numGlobals();
bool hasMutableGlobals =
- out.targetFeaturesSec->features.count("mutable-globals") > 0;
+ out.targetFeaturesSec->features.contains("mutable-globals");
for (Symbol *sym : symtab->symbols()) {
if (!sym->isExported())
@@ -1042,7 +1042,7 @@ void Writer::createOutputSegments() {
if (ctx.arg.relocatable && !segment->getComdatName().empty()) {
s = createOutputSegment(name);
} else {
- if (segmentMap.count(name) == 0)
+ if (!segmentMap.contains(name))
segmentMap[name] = createOutputSegment(name);
s = segmentMap[name];
}
More information about the llvm-commits
mailing list