[lld] r270347 - Use StringPiece::Size instead of calculating it again. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat May 21 18:03:42 PDT 2016


Author: ruiu
Date: Sat May 21 20:03:41 2016
New Revision: 270347

URL: http://llvm.org/viewvc/llvm-project?rev=270347&view=rev
Log:
Use StringPiece::Size instead of calculating it again. NFC.

Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=270347&r1=270346&r2=270347&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Sat May 21 20:03:41 2016
@@ -978,11 +978,8 @@ EHRegion<ELFT>::EHRegion(EHInputSection<
 
 template <class ELFT> ArrayRef<uint8_t> EHRegion<ELFT>::data() const {
   ArrayRef<uint8_t> SecData = Sec->getSectionData();
-  size_t Start = Sec->Pieces[Index].InputOff;
-  size_t End = (Index == Sec->Pieces.size() - 1)
-                   ? SecData.size()
-                   : Sec->Pieces[Index + 1].InputOff;
-  return SecData.slice(Start, End - Start);
+  SectionPiece &Piece = Sec->Pieces[Index];
+  return SecData.slice(Piece.InputOff, Piece.Size);
 }
 
 template <class ELFT>
@@ -1279,35 +1276,20 @@ void MergeOutputSection<ELFT>::addSectio
   auto *Sec = cast<MergeInputSection<ELFT>>(C);
   Sec->OutSec = this;
   this->updateAlign(Sec->Align);
+  this->Header.sh_entsize = Sec->getSectionHdr()->sh_entsize;
 
   ArrayRef<uint8_t> D = Sec->getSectionData();
   StringRef Data((const char *)D.data(), D.size());
-  uintX_t EntSize = Sec->getSectionHdr()->sh_entsize;
-  this->Header.sh_entsize = EntSize;
+  bool IsString = this->Header.sh_flags & SHF_STRINGS;
 
-  // If this is of type string, the contents are null-terminated strings.
-  if (this->Header.sh_flags & SHF_STRINGS) {
-    for (unsigned I = 0, N = Sec->Pieces.size(); I != N; ++I) {
-      SectionPiece &Piece = Sec->Pieces[I];
-      if (!Piece.Live)
-        continue;
-
-      uintX_t Start = Piece.InputOff;
-      uintX_t End = (I == N - 1) ? Data.size() : Sec->Pieces[I + 1].InputOff;
-      StringRef Entry = Data.substr(Start, End - Start);
-      uintX_t OutputOffset = Builder.add(Entry);
-      if (!shouldTailMerge())
-        Piece.OutputOff = OutputOffset;
-    }
-    return;
-  }
-
-  // If this is not of type string, every entry has the same size.
-  for (SectionPiece &Piece : Sec->Pieces) {
+  for (size_t I = 0, N = Sec->Pieces.size(); I != N; ++I) {
+    SectionPiece &Piece = Sec->Pieces[I];
     if (!Piece.Live)
       continue;
-    StringRef Entry = Data.substr(Piece.InputOff, EntSize);
-    Piece.OutputOff = Builder.add(Entry);
+    StringRef Entry = Data.substr(Piece.InputOff, Piece.Size);
+    uintX_t OutputOffset = Builder.add(Entry);
+    if (!IsString || !shouldTailMerge())
+      Piece.OutputOff = OutputOffset;
   }
 }
 




More information about the llvm-commits mailing list