From f34c088515a414f67e781a174a1c5fcfcd5fab1b Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 25 Jun 2015 17:56:36 +0000 Subject: [PATCH] COFF: Simplify. NFC. llvm-svn: 240666 --- lld/COFF/Chunks.cpp | 20 ++++++++++---------- lld/COFF/Chunks.h | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index fde2407..2acc722 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -59,9 +59,8 @@ void SectionChunk::writeTo(uint8_t *Buf) { if (!hasData()) return; // Copy section contents from source object file to output file. - ArrayRef Data; - File->getCOFFObj()->getSectionContents(Header, Data); - memcpy(Buf + FileOff, Data.data(), Data.size()); + ArrayRef A = getContents(); + memcpy(Buf + FileOff, A.data(), A.size()); // Apply relocations. for (const coff_relocation &Rel : Relocs) { @@ -155,8 +154,7 @@ StringRef SectionChunk::getDebugName() { } uint64_t SectionChunk::getHash() const { - ArrayRef A; - File->getCOFFObj()->getSectionContents(Header, A); + ArrayRef A = getContents(); return hash_combine(getPermissions(), llvm::hash_value(SectionName), NumRelocs, @@ -178,11 +176,7 @@ bool SectionChunk::equals(const SectionChunk *X) const { return false; // Compare data - ArrayRef A, B; - File->getCOFFObj()->getSectionContents(Header, A); - X->File->getCOFFObj()->getSectionContents(X->Header, B); - assert(A.size() == B.size()); - if (memcmp(A.data(), B.data(), A.size())) + if (getContents() != X->getContents()) return false; // Compare relocations @@ -202,6 +196,12 @@ bool SectionChunk::equals(const SectionChunk *X) const { return std::equal(Relocs.begin(), Relocs.end(), X->Relocs.begin(), Eq); } +ArrayRef SectionChunk::getContents() const { + ArrayRef A; + File->getCOFFObj()->getSectionContents(Header, A); + return A; +} + // Returns a pointer to this chunk or its replacement. SectionChunk *SectionChunk::repl() { while (Ptr != Ptr->Ptr) diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index 3f15c16..6522f00 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -150,6 +150,7 @@ public: private: void mark() override; + ArrayRef getContents() const; // A file this chunk was created from. ObjectFile *File; -- 2.7.4