From e8a077badf852530077c8abda9d9d1737b44140c Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Sat, 26 Nov 2016 15:15:11 +0000 Subject: [PATCH] Change return types of split{Non,}Strings. They return new vectors, but at the same time they mutate other vectors, so returning values doesn't make much sense. We should just mutate two vectors. llvm-svn: 287979 --- lld/ELF/InputSection.cpp | 21 ++++++++------------- lld/ELF/InputSection.h | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 07bb8fd..e3eb422 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -703,9 +703,8 @@ static size_t findNull(ArrayRef A, size_t EntSize) { // Split SHF_STRINGS section. Such section is a sequence of // null-terminated strings. template -std::vector -MergeInputSection::splitStrings(ArrayRef Data, size_t EntSize) { - std::vector V; +void MergeInputSection::splitStrings(ArrayRef Data, + size_t EntSize) { size_t Off = 0; bool IsAlloc = this->Flags & SHF_ALLOC; while (!Data.empty()) { @@ -713,12 +712,11 @@ MergeInputSection::splitStrings(ArrayRef Data, size_t EntSize) { if (End == StringRef::npos) fatal(toString(this) + ": string is not null terminated"); size_t Size = End + EntSize; - V.emplace_back(Off, !IsAlloc); + Pieces.emplace_back(Off, !IsAlloc); Hashes.push_back(hash_value(toStringRef(Data.slice(0, Size)))); Data = Data.slice(Size); Off += Size; } - return V; } // Returns I'th piece's data. @@ -734,18 +732,15 @@ CachedHashStringRef MergeInputSection::getData(size_t I) const { // Split non-SHF_STRINGS section. Such section is a sequence of // fixed size records. template -std::vector -MergeInputSection::splitNonStrings(ArrayRef Data, - size_t EntSize) { - std::vector V; +void MergeInputSection::splitNonStrings(ArrayRef Data, + size_t EntSize) { size_t Size = Data.size(); assert((Size % EntSize) == 0); bool IsAlloc = this->Flags & SHF_ALLOC; for (unsigned I = 0, N = Size; I != N; I += EntSize) { Hashes.push_back(hash_value(toStringRef(Data.slice(I, EntSize)))); - V.emplace_back(I, !IsAlloc); + Pieces.emplace_back(I, !IsAlloc); } - return V; } template @@ -764,9 +759,9 @@ template void MergeInputSection::splitIntoPieces() { ArrayRef Data = this->Data; uintX_t EntSize = this->Entsize; if (this->Flags & SHF_STRINGS) - this->Pieces = splitStrings(Data, EntSize); + splitStrings(Data, EntSize); else - this->Pieces = splitNonStrings(Data, EntSize); + splitNonStrings(Data, EntSize); if (Config->GcSections && (this->Flags & SHF_ALLOC)) for (uintX_t Off : LiveOffsets) diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 78c217f..28c14b0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -201,8 +201,8 @@ public: const SectionPiece *getSectionPiece(uintX_t Offset) const; private: - std::vector splitStrings(ArrayRef A, size_t Size); - std::vector splitNonStrings(ArrayRef A, size_t Size); + void splitStrings(ArrayRef A, size_t Size); + void splitNonStrings(ArrayRef A, size_t Size); std::vector Hashes; -- 2.7.4