[PATCH] D118916: [lld-macho][nfc] Minor clean up
Vy Nguyen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 3 08:47:49 PST 2022
oontvoo created this revision.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
- change the vector of relocs to std::list for ptr stability. (This field is not needed to have fast access per index anyway. This should also make the remove/erase ops faster)
- when checking for entry existance use, `.find()` rather than the `[]` operator, which would actually create a new entry in the map.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118916
Files:
lld/MachO/Driver.cpp
lld/MachO/InputSection.cpp
lld/MachO/InputSection.h
lld/MachO/UnwindInfoSection.cpp
Index: lld/MachO/UnwindInfoSection.cpp
===================================================================
--- lld/MachO/UnwindInfoSection.cpp
+++ lld/MachO/UnwindInfoSection.cpp
@@ -198,8 +198,7 @@
// work. But since there are usually just few personality functions
// that are referenced from many places, at least some of them likely
// live, it wouldn't reduce number of got entries.
- for (size_t i = 0; i < isec->relocs.size(); ++i) {
- Reloc &r = isec->relocs[i];
+ for (Reloc &r : isec->relocs) {
assert(target->hasAttr(r.type, RelocAttrBits::UNSIGNED));
// Functions and LSDA entries always reside in the same object file as the
Index: lld/MachO/InputSection.h
===================================================================
--- lld/MachO/InputSection.h
+++ lld/MachO/InputSection.h
@@ -21,6 +21,8 @@
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/BinaryFormat/MachO.h"
+#include <list>
+
namespace lld {
namespace macho {
@@ -62,7 +64,7 @@
bool isFinal = false;
ArrayRef<uint8_t> data;
- std::vector<Reloc> relocs;
+ std::list<Reloc> relocs;
// The symbols that belong to this InputSection, sorted by value. With
// .subsections_via_symbols, there is typically only one element here.
llvm::TinyPtrVector<Defined *> symbols;
Index: lld/MachO/InputSection.cpp
===================================================================
--- lld/MachO/InputSection.cpp
+++ lld/MachO/InputSection.cpp
@@ -139,13 +139,14 @@
memcpy(buf, data.data(), data.size());
- for (size_t i = 0; i < relocs.size(); i++) {
- const Reloc &r = relocs[i];
+ for (auto it = relocs.begin(); it != relocs.end(); ++it) {
+ const Reloc &r = *it;
uint8_t *loc = buf + r.offset;
uint64_t referentVA = 0;
if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) {
const Symbol *fromSym = r.referent.get<Symbol *>();
- const Reloc &minuend = relocs[++i];
+ ++it;
+ const Reloc &minuend = *it;
uint64_t minuendVA;
if (const Symbol *toSym = minuend.referent.dyn_cast<Symbol *>())
minuendVA = toSym->getVA() + minuend.addend;
Index: lld/MachO/Driver.cpp
===================================================================
--- lld/MachO/Driver.cpp
+++ lld/MachO/Driver.cpp
@@ -267,8 +267,9 @@
// We don't take a reference to cachedFile here because the
// loadArchiveMember() call below may recursively call addFile() and
// invalidate this reference.
- if (ArchiveFile *cachedFile = loadedArchives[path])
- return cachedFile;
+ auto entry = loadedArchives.find(path);
+ if (entry != loadedArchives.end())
+ return entry->second;
std::unique_ptr<object::Archive> archive = CHECK(
object::Archive::create(mbref), path + ": failed to parse archive");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118916.405670.patch
Type: text/x-patch
Size: 2801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220203/5ced9b3c/attachment.bin>
More information about the llvm-commits
mailing list