By using emplace_back, as well as converting some loops to for-each, we can do more efficient vectorization.
Make copy constructor for TemporaryFile noexcept.
Reviewed By: #lld-macho, int3
Differential Revision: https://reviews.llvm.org/D139552
}
// sizeInBits is used to initialize the Flags field; currently no
// other flags are defined.
- res.emplace_back(
- RuntimePseudoReloc(target, this, rel.VirtualAddress, sizeInBits));
+ res.emplace_back(target, this, rel.VirtualAddress, sizeInBits);
}
}
}
// Construct search path list.
- searchPaths.push_back("");
+ searchPaths.emplace_back("");
for (auto *arg : args.filtered(OPT_libpath))
searchPaths.push_back(arg->getValue());
detectWinSysRoot(args);
}
}
- TemporaryFile(TemporaryFile &&obj) {
- std::swap(path, obj.path);
- }
+ TemporaryFile(TemporaryFile &&obj) noexcept { std::swap(path, obj.path); }
~TemporaryFile() {
if (path.empty())
ctx.config.argv = {argv[0]};
for (opt::Arg *arg : args) {
if (arg->getOption().getKind() != opt::Option::InputClass) {
- ctx.config.argv.push_back(args.getArgString(arg->getIndex()));
+ ctx.config.argv.emplace_back(args.getArgString(arg->getIndex()));
}
}
// Update pointers in input files.
parallelForEach(ctx.objFileInstances, [&](ObjFile *file) {
MutableArrayRef<Symbol *> syms = file->getMutableSymbols();
- for (size_t i = 0, e = syms.size(); i != e; ++i)
- if (Symbol *s = map.lookup(syms[i]))
- syms[i] = s;
+ for (auto &sym : syms)
+ if (Symbol *s = map.lookup(sym))
+ sym = s;
});
}
uint32_t &thunkSymbolIndex = insertion.first->second;
if (insertion.second)
thunkSymbolIndex = file->addRangeThunkSymbol(thunk);
- relocReplacements.push_back({j, thunkSymbolIndex});
+ relocReplacements.emplace_back(j, thunkSymbolIndex);
}
// Get a writable copy of this section's relocations so they can be
continue;
ArrayRef<coff_relocation> relocs = sc->getRelocs();
- for (size_t j = 0, e = relocs.size(); j < e; ++j) {
- const coff_relocation &rel = relocs[j];
+ for (const coff_relocation &rel : relocs) {
Symbol *relocTarget = sc->file->getSymbol(rel.SymbolTableIndex);
Defined *sym = dyn_cast_or_null<Defined>(relocTarget);
// allowing a debugger to match a PDB and an executable. So we need it even
// if we're ultimately not going to write CodeView data to the PDB.
buildId = make<CVDebugRecordChunk>(ctx);
- debugRecords.push_back({COFF::IMAGE_DEBUG_TYPE_CODEVIEW, buildId});
+ debugRecords.emplace_back(COFF::IMAGE_DEBUG_TYPE_CODEVIEW, buildId);
}
if (config->cetCompat) {
- debugRecords.push_back({COFF::IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS,
- make<ExtendedDllCharacteristicsChunk>(
- IMAGE_DLL_CHARACTERISTICS_EX_CET_COMPAT)});
+ debugRecords.emplace_back(COFF::IMAGE_DEBUG_TYPE_EX_DLLCHARACTERISTICS,
+ make<ExtendedDllCharacteristicsChunk>(
+ IMAGE_DLL_CHARACTERISTICS_EX_CET_COMPAT));
}
// Align and add each chunk referenced by the debug data directory.
// user programs can access blobs by name. Non-alphanumeric
// characters in a filename are replaced with underscore.
std::string s = "_binary_" + mb.getBufferIdentifier().str();
- for (size_t i = 0; i < s.size(); ++i)
- if (!isAlnum(s[i]))
- s[i] = '_';
+ for (char &c : s)
+ if (!isAlnum(c))
+ c = '_';
llvm::StringSaver &saver = lld::saver();
os << right_justify("VMA", w) << ' ' << right_justify("LMA", w)
<< " Size Align Out In Symbol\n";
- OutputSection* osec = nullptr;
+ OutputSection *osec = nullptr;
for (SectionCommand *cmd : script->sectionCommands) {
if (auto *assign = dyn_cast<SymbolAssignment>(cmd)) {
if (assign->provide && !assign->sym)
llvm::function_ref<int(InputSectionBase *s)> order) {
std::vector<std::pair<int, InputSection *>> v;
for (InputSection *s : in)
- v.push_back({order(s), s});
+ v.emplace_back(order(s), s);
llvm::stable_sort(v, less_first());
for (size_t i = 0; i < v.size(); ++i)
thunk->align = 4;
thunk->data = {reinterpret_cast<const uint8_t *>(thunkCode),
sizeof(thunkCode)};
- thunk->relocs.push_back({/*type=*/ARM64_RELOC_PAGEOFF12,
- /*pcrel=*/false, /*length=*/2,
- /*offset=*/4, /*addend=*/0,
- /*referent=*/funcSym});
- thunk->relocs.push_back({/*type=*/ARM64_RELOC_PAGE21,
- /*pcrel=*/true, /*length=*/2,
- /*offset=*/0, /*addend=*/0,
- /*referent=*/funcSym});
+ thunk->relocs.emplace_back(/*type=*/ARM64_RELOC_PAGEOFF12,
+ /*pcrel=*/false, /*length=*/2,
+ /*offset=*/4, /*addend=*/0,
+ /*referent=*/funcSym);
+ thunk->relocs.emplace_back(/*type=*/ARM64_RELOC_PAGE21,
+ /*pcrel=*/true, /*length=*/2,
+ /*offset=*/0, /*addend=*/0,
+ /*referent=*/funcSym);
}
ARM64::ARM64() : ARM64Common(LP64()) {
void addEntry(const InputSection *isec, uint64_t offset) {
if (config->isPic)
- locations.push_back({isec, offset});
+ locations.emplace_back(isec, offset);
}
private:
int64_t addend;
Location target;
BindingEntry(int64_t addend, Location target)
- : addend(addend), target(std::move(target)) {}
+ : addend(addend), target(target) {}
};
template <class Sym>