[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
This commit is contained in:
parent
00fecbcf00
commit
53c237c006
@ -15,12 +15,12 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/StringSet.h"
|
||||
#include "llvm/Object/COFF.h"
|
||||
#include "llvm/Support/CachePruning.h"
|
||||
#include "llvm/Support/VirtualFileSystem.h"
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
namespace lld::coff {
|
||||
@ -155,14 +155,14 @@ struct Configuration {
|
||||
// Symbols in this set are considered as live by the garbage collector.
|
||||
std::vector<Symbol *> gcroot;
|
||||
|
||||
std::set<std::string> noDefaultLibs;
|
||||
llvm::StringSet<> noDefaultLibs;
|
||||
bool noDefaultLibAll = false;
|
||||
|
||||
// True if we are creating a DLL.
|
||||
bool dll = false;
|
||||
StringRef implib;
|
||||
bool noimplib = false;
|
||||
std::set<std::string> delayLoads;
|
||||
llvm::StringSet<> delayLoads;
|
||||
std::map<std::string, int> dllOrder;
|
||||
Symbol *arm64ECIcallHelper = nullptr;
|
||||
|
||||
|
||||
@ -23,6 +23,7 @@
|
||||
#include "lld/Common/Timer.h"
|
||||
#include "lld/Common/Version.h"
|
||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/BinaryFormat/Magic.h"
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
@ -715,7 +716,7 @@ std::optional<StringRef> LinkerDriver::findLibIfNew(StringRef filename) {
|
||||
return std::nullopt;
|
||||
|
||||
StringRef path = findLib(filename);
|
||||
if (ctx.config.noDefaultLibs.count(path.lower()))
|
||||
if (ctx.config.noDefaultLibs.contains(path.lower()))
|
||||
return std::nullopt;
|
||||
|
||||
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
|
||||
@ -864,9 +865,9 @@ void LinkerDriver::addWinSysRootLibSearchPaths() {
|
||||
|
||||
// Libraries specified by `/nodefaultlib:` may not be found in incomplete
|
||||
// search paths before lld infers a machine type from input files.
|
||||
std::set<std::string> noDefaultLibs;
|
||||
for (const std::string &path : ctx.config.noDefaultLibs)
|
||||
noDefaultLibs.insert(findLib(path).lower());
|
||||
llvm::StringSet<> noDefaultLibs;
|
||||
for (auto &iter : ctx.config.noDefaultLibs)
|
||||
noDefaultLibs.insert(findLib(iter.first()).lower());
|
||||
ctx.config.noDefaultLibs = noDefaultLibs;
|
||||
}
|
||||
|
||||
@ -1153,7 +1154,7 @@ void LinkerDriver::parseOrderFile(StringRef arg) {
|
||||
if (ctx.config.machine == I386 && !isDecorated(s))
|
||||
s = "_" + s;
|
||||
|
||||
if (set.count(s) == 0) {
|
||||
if (!set.contains(s)) {
|
||||
if (ctx.config.warnMissingOrderSymbol)
|
||||
Warn(ctx) << "/order:" << arg << ": missing symbol: " << s
|
||||
<< " [LNK4037]";
|
||||
@ -2284,7 +2285,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
|
||||
if (errCount(ctx))
|
||||
return;
|
||||
|
||||
std::set<sys::fs::UniqueID> wholeArchives;
|
||||
SmallSet<sys::fs::UniqueID, 0> wholeArchives;
|
||||
for (auto *arg : args.filtered(OPT_wholearchive_file))
|
||||
if (std::optional<StringRef> path = findFile(arg->getValue()))
|
||||
if (std::optional<sys::fs::UniqueID> id = getUniqueID(*path))
|
||||
@ -2298,7 +2299,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
|
||||
if (args.hasArg(OPT_wholearchive_flag))
|
||||
return true;
|
||||
if (std::optional<sys::fs::UniqueID> id = getUniqueID(path))
|
||||
return wholeArchives.count(*id);
|
||||
return wholeArchives.contains(*id);
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
@ -150,7 +150,8 @@ bool AutoExporter::shouldExport(Defined *sym) const {
|
||||
// disallow import symbols.
|
||||
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
|
||||
return false;
|
||||
if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName()))
|
||||
if (excludeSymbols.contains(sym->getName()) ||
|
||||
manualExcludeSymbols.contains(sym->getName()))
|
||||
return false;
|
||||
|
||||
for (StringRef prefix : excludeSymbolPrefixes.keys())
|
||||
@ -174,10 +175,10 @@ bool AutoExporter::shouldExport(Defined *sym) const {
|
||||
// Drop the file extension.
|
||||
libName = libName.substr(0, libName.rfind('.'));
|
||||
if (!libName.empty())
|
||||
return !excludeLibs.count(libName);
|
||||
return !excludeLibs.contains(libName);
|
||||
|
||||
StringRef fileName = sys::path::filename(sym->getFile()->getName());
|
||||
return !excludeObjects.count(fileName);
|
||||
return !excludeObjects.contains(fileName);
|
||||
}
|
||||
|
||||
void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name,
|
||||
|
||||
@ -381,7 +381,7 @@ void SymbolTable::reportProblemSymbols(
|
||||
return;
|
||||
|
||||
for (Symbol *b : ctx.config.gcroot) {
|
||||
if (undefs.count(b))
|
||||
if (undefs.contains(b))
|
||||
errorOrWarn(ctx) << "<root>: undefined symbol: " << printSymbol(b);
|
||||
if (localImports)
|
||||
if (Symbol *imp = localImports->lookup(b))
|
||||
@ -399,7 +399,7 @@ void SymbolTable::reportProblemSymbols(
|
||||
++symIndex;
|
||||
if (!sym)
|
||||
continue;
|
||||
if (undefs.count(sym)) {
|
||||
if (undefs.contains(sym)) {
|
||||
auto [it, inserted] = firstDiag.try_emplace(sym, undefDiags.size());
|
||||
if (inserted)
|
||||
undefDiags.push_back({sym, {{file, symIndex}}});
|
||||
|
||||
@ -1330,7 +1330,7 @@ void Writer::createImportTables() {
|
||||
if (file->impSym && !isa<DefinedImportData>(file->impSym))
|
||||
Fatal(ctx) << file->symtab.printSymbol(file->impSym) << " was replaced";
|
||||
DefinedImportData *impSym = cast_or_null<DefinedImportData>(file->impSym);
|
||||
if (ctx.config.delayLoads.count(StringRef(file->dllName).lower())) {
|
||||
if (ctx.config.delayLoads.contains(StringRef(file->dllName).lower())) {
|
||||
if (!file->thunkSym)
|
||||
Fatal(ctx) << "cannot delay-load " << toString(file)
|
||||
<< " due to import of data: "
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user