Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53c237c

Browse files
authored
[lld][COFF] Use .contains rather than .count for set membership. NFC (#177067)
Also converted a couple of `std::set` to `llvm::StringSet`/`llvm::SmallSet`. This matches the usage in the other linker backends. See #176610
1 parent 00fecbc commit 53c237c

5 files changed

Lines changed: 18 additions & 16 deletions

File tree

lld/COFF/Config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#include "llvm/ADT/SmallVector.h"
1616
#include "llvm/ADT/StringMap.h"
1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/ADT/StringSet.h"
1819
#include "llvm/Object/COFF.h"
1920
#include "llvm/Support/CachePruning.h"
2021
#include "llvm/Support/VirtualFileSystem.h"
2122
#include <cstdint>
2223
#include <map>
23-
#include <set>
2424
#include <string>
2525

2626
namespace lld::coff {
@@ -155,14 +155,14 @@ struct Configuration {
155155
// Symbols in this set are considered as live by the garbage collector.
156156
std::vector<Symbol *> gcroot;
157157

158-
std::set<std::string> noDefaultLibs;
158+
llvm::StringSet<> noDefaultLibs;
159159
bool noDefaultLibAll = false;
160160

161161
// True if we are creating a DLL.
162162
bool dll = false;
163163
StringRef implib;
164164
bool noimplib = false;
165-
std::set<std::string> delayLoads;
165+
llvm::StringSet<> delayLoads;
166166
std::map<std::string, int> dllOrder;
167167
Symbol *arm64ECIcallHelper = nullptr;
168168

lld/COFF/Driver.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "lld/Common/Timer.h"
2424
#include "lld/Common/Version.h"
2525
#include "llvm/ADT/IntrusiveRefCntPtr.h"
26+
#include "llvm/ADT/SmallSet.h"
2627
#include "llvm/ADT/StringSwitch.h"
2728
#include "llvm/BinaryFormat/Magic.h"
2829
#include "llvm/Config/llvm-config.h"
@@ -715,7 +716,7 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
715716
return std::nullopt;
716717

717718
StringRef path = findLib(filename);
718-
if (ctx.config.noDefaultLibs.count(path.lower()))
719+
if (ctx.config.noDefaultLibs.contains(path.lower()))
719720
return std::nullopt;
720721

721722
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
@@ -864,9 +865,9 @@ void LinkerDriver::addWinSysRootLibSearchPaths() {
864865

865866
// Libraries specified by `/nodefaultlib:` may not be found in incomplete
866867
// search paths before lld infers a machine type from input files.
867-
std::set<std::string> noDefaultLibs;
868-
for (const std::string &path : ctx.config.noDefaultLibs)
869-
noDefaultLibs.insert(findLib(path).lower());
868+
llvm::StringSet<> noDefaultLibs;
869+
for (auto &iter : ctx.config.noDefaultLibs)
870+
noDefaultLibs.insert(findLib(iter.first()).lower());
870871
ctx.config.noDefaultLibs = noDefaultLibs;
871872
}
872873

@@ -1153,7 +1154,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
11531154
if (ctx.config.machine == I386 && !isDecorated(s))
11541155
s = "_" + s;
11551156

1156-
if (set.count(s) == 0) {
1157+
if (!set.contains(s)) {
11571158
if (ctx.config.warnMissingOrderSymbol)
11581159
Warn(ctx) << "/order:" << arg << ": missing symbol: " << s
11591160
<< " [LNK4037]";
@@ -2284,7 +2285,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22842285
if (errCount(ctx))
22852286
return;
22862287

2287-
std::set<sys::fs::UniqueID> wholeArchives;
2288+
SmallSet<sys::fs::UniqueID, 0> wholeArchives;
22882289
for (auto *arg : args.filtered(OPT_wholearchive_file))
22892290
if (std::optional<StringRef> path = findFile(arg->getValue()))
22902291
if (std::optional<sys::fs::UniqueID> id = getUniqueID(*path))
@@ -2298,7 +2299,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
22982299
if (args.hasArg(OPT_wholearchive_flag))
22992300
return true;
23002301
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
2301-
return wholeArchives.count(*id);
2302+
return wholeArchives.contains(*id);
23022303
return false;
23032304
};
23042305

lld/COFF/MinGW.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ bool AutoExporter::shouldExport(Defined *sym) const {
150150
// disallow import symbols.
151151
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
152152
return false;
153-
if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName()))
153+
if (excludeSymbols.contains(sym->getName()) ||
154+
manualExcludeSymbols.contains(sym->getName()))
154155
return false;
155156

156157
for (StringRef prefix : excludeSymbolPrefixes.keys())
@@ -174,10 +175,10 @@ bool AutoExporter::shouldExport(Defined *sym) const {
174175
// Drop the file extension.
175176
libName = libName.substr(0, libName.rfind('.'));
176177
if (!libName.empty())
177-
return !excludeLibs.count(libName);
178+
return !excludeLibs.contains(libName);
178179

179180
StringRef fileName = sys::path::filename(sym->getFile()->getName());
180-
return !excludeObjects.count(fileName);
181+
return !excludeObjects.contains(fileName);
181182
}
182183

183184
void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,

lld/COFF/SymbolTable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void SymbolTable::reportProblemSymbols(
381381
return;
382382

383383
for (Symbol *b : ctx.config.gcroot) {
384-
if (undefs.count(b))
384+
if (undefs.contains(b))
385385
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
386386
if (localImports)
387387
if (Symbol *imp = localImports->lookup(b))
@@ -399,7 +399,7 @@ void SymbolTable::reportProblemSymbols(
399399
++symIndex;
400400
if (!sym)
401401
continue;
402-
if (undefs.count(sym)) {
402+
if (undefs.contains(sym)) {
403403
auto [it, inserted] = firstDiag.try_emplace(sym, undefDiags.size());
404404
if (inserted)
405405
undefDiags.push_back({sym, {{file, symIndex}}});

lld/COFF/Writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,7 @@ void Writer::createImportTables() {
13301330
if (file->impSym && !isa<DefinedImportData>(file->impSym))
13311331
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
13321332
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
1333-
if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
1333+
if (ctx.config.delayLoads.contains(StringRef(file->dllName).lower())) {
13341334
if (!file->thunkSym)
13351335
Fatal(ctx) << "cannot delay-load " << toString(file)
13361336
<< " due to import of data: "

0 commit comments

Comments
 (0)