Simplify SplitInputSection::getRangeAndSize.

This patch adds Size member to SectionPiece so that getRangeAndSize
can just return a SectionPiece instead of a std::pair<SectionPiece *, uint_t>.
Also renamed the function.

llvm-svn: 270346
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 58e8e63..592f152 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -414,7 +414,7 @@
   // identify the start of the output .eh_frame. Handle this special case.
   if (this->getSectionHdr()->sh_size == 0)
     return Offset;
-  SectionPiece *Piece = this->getRangeAndSize(Offset).first;
+  SectionPiece *Piece = this->getSectionPiece(Offset);
   if (Piece->OutputOff == size_t(-1))
     return -1; // Not in the output
 
@@ -449,8 +449,8 @@
       size_t End = findNull(Data, EntSize);
       if (End == StringRef::npos)
         fatal("string is not null terminated");
-      this->Pieces.emplace_back(Offset);
       uintX_t Size = End + EntSize;
+      this->Pieces.emplace_back(Offset, Size);
       Data = Data.substr(Size);
       Offset += Size;
     }
@@ -461,7 +461,7 @@
   size_t Size = Data.size();
   assert((Size % EntSize) == 0);
   for (unsigned I = 0, N = Size; I != N; I += EntSize)
-    this->Pieces.emplace_back(I);
+    this->Pieces.emplace_back(I, EntSize);
 }
 
 template <class ELFT>
@@ -470,8 +470,7 @@
 }
 
 template <class ELFT>
-std::pair<SectionPiece *, typename ELFT::uint>
-SplitInputSection<ELFT>::getRangeAndSize(uintX_t Offset) {
+SectionPiece *SplitInputSection<ELFT>::getSectionPiece(uintX_t Offset) {
   ArrayRef<uint8_t> D = this->getSectionData();
   StringRef Data((const char *)D.data(), D.size());
   uintX_t Size = Data.size();
@@ -482,16 +481,13 @@
   auto I = std::upper_bound(
       Pieces.begin(), Pieces.end(), Offset,
       [](const uintX_t &A, const SectionPiece &B) { return A < B.InputOff; });
-  uintX_t End = (I == Pieces.end()) ? Data.size() : I->InputOff;
   --I;
-  return {&*I, End};
+  return &*I;
 }
 
 template <class ELFT>
 typename ELFT::uint MergeInputSection<ELFT>::getOffset(uintX_t Offset) {
-  std::pair<SectionPiece *, uintX_t> T = this->getRangeAndSize(Offset);
-  SectionPiece &Piece = *T.first;
-  uintX_t End = T.second;
+  SectionPiece &Piece = *this->getSectionPiece(Offset);
   assert(Piece.Live);
 
   // Compute the Addend and if the Base is cached, return.
@@ -502,7 +498,7 @@
   // Map the base to the offset in the output section and cache it.
   ArrayRef<uint8_t> D = this->getSectionData();
   StringRef Data((const char *)D.data(), D.size());
-  StringRef Entry = Data.substr(Piece.InputOff, End - Piece.InputOff);
+  StringRef Entry = Data.substr(Piece.InputOff, Piece.Size);
   auto *MOS = static_cast<MergeOutputSection<ELFT> *>(this->OutSec);
   Piece.OutputOff = MOS->getOffset(Entry);
   return Piece.OutputOff + Addend;
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index f245859..aec4c38 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -132,8 +132,10 @@
 
 // SectionPiece represents a piece of splittable section contents.
 struct SectionPiece {
-  SectionPiece(size_t I) : InputOff(I), Live(!Config->GcSections) {}
+  SectionPiece(size_t Off, size_t Size)
+      : InputOff(Off), Size(Size), Live(!Config->GcSections) {}
   size_t InputOff;
+  size_t Size;
   size_t OutputOff = -1;
   bool Live;
 };
@@ -154,7 +156,7 @@
   // rather than a single large blob of data.
   std::vector<SectionPiece> Pieces;
 
-  std::pair<SectionPiece *, uintX_t> getRangeAndSize(uintX_t Offset);
+  SectionPiece *getSectionPiece(uintX_t Offset);
 };
 
 // This corresponds to a SHF_MERGE section of an input file.
diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp
index 6680f69..87ff847 100644
--- a/lld/ELF/MarkLive.cpp
+++ b/lld/ELF/MarkLive.cpp
@@ -136,15 +136,14 @@
 // Starting from GC-root sections, this function visits all reachable
 // sections to set their "Live" bits.
 template <class ELFT> void elf::markLive() {
-  typedef typename ELFT::uint uintX_t;
   SmallVector<InputSection<ELFT> *, 256> Q;
 
   auto Enqueue = [&](ResolvedReloc<ELFT> R) {
     if (!R.Sec)
       return;
     if (auto *MS = dyn_cast<MergeInputSection<ELFT>>(R.Sec)) {
-      std::pair<SectionPiece *, uintX_t> T = MS->getRangeAndSize(R.Offset);
-      T.first->Live = true;
+      SectionPiece *Piece = MS->getSectionPiece(R.Offset);
+      Piece->Live = true;
     }
     if (R.Sec->Live)
       return;
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index d54b9c4..c235583 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -1142,9 +1142,6 @@
 
   DenseMap<uintX_t, uintX_t> OffsetToIndex;
   while (!D.empty()) {
-    unsigned Index = Sec->Pieces.size();
-    Sec->Pieces.emplace_back(Offset);
-
     uintX_t Length = readEntryLength<ELFT>(D);
     // If CIE/FDE data length is zero then Length is 4, this
     // shall be considered a terminator and processing shall end.
@@ -1152,6 +1149,9 @@
       break;
     StringRef Entry((const char *)D.data(), Length);
 
+    unsigned Index = Sec->Pieces.size();
+    Sec->Pieces.emplace_back(Offset, Length);
+
     uint32_t ID = read32<E>(D.data() + 4);
     if (ID == 0) {
       // CIE
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0105991..1f84102 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -855,7 +855,7 @@
     if (!D->Section->Live)
       return false;
     if (auto *S = dyn_cast<MergeInputSection<ELFT>>(D->Section))
-      if (!S->getRangeAndSize(D->Value).first->Live)
+      if (!S->getSectionPiece(D->Value)->Live)
         return false;
   }
   return true;