[lld] r287979 - Change return types of split{Non,}Strings.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 26 07:15:11 PST 2016


Author: ruiu
Date: Sat Nov 26 09:15:11 2016
New Revision: 287979

URL: http://llvm.org/viewvc/llvm-project?rev=287979&view=rev
Log:
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.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=287979&r1=287978&r2=287979&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sat Nov 26 09:15:11 2016
@@ -703,9 +703,8 @@ static size_t findNull(ArrayRef<uint8_t>
 // Split SHF_STRINGS section. Such section is a sequence of
 // null-terminated strings.
 template <class ELFT>
-std::vector<SectionPiece>
-MergeInputSection<ELFT>::splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {
-  std::vector<SectionPiece> V;
+void MergeInputSection<ELFT>::splitStrings(ArrayRef<uint8_t> Data,
+                                           size_t EntSize) {
   size_t Off = 0;
   bool IsAlloc = this->Flags & SHF_ALLOC;
   while (!Data.empty()) {
@@ -713,12 +712,11 @@ MergeInputSection<ELFT>::splitStrings(Ar
     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<EL
 // Split non-SHF_STRINGS section. Such section is a sequence of
 // fixed size records.
 template <class ELFT>
-std::vector<SectionPiece>
-MergeInputSection<ELFT>::splitNonStrings(ArrayRef<uint8_t> Data,
-                                         size_t EntSize) {
-  std::vector<SectionPiece> V;
+void MergeInputSection<ELFT>::splitNonStrings(ArrayRef<uint8_t> 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 <class ELFT>
@@ -764,9 +759,9 @@ template <class ELFT> void MergeInputSec
   ArrayRef<uint8_t> 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)

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=287979&r1=287978&r2=287979&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sat Nov 26 09:15:11 2016
@@ -201,8 +201,8 @@ public:
   const SectionPiece *getSectionPiece(uintX_t Offset) const;
 
 private:
-  std::vector<SectionPiece> splitStrings(ArrayRef<uint8_t> A, size_t Size);
-  std::vector<SectionPiece> splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
+  void splitStrings(ArrayRef<uint8_t> A, size_t Size);
+  void splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
 
   std::vector<uint32_t> Hashes;
 




More information about the llvm-commits mailing list