[lld] r348311 - [ELF] Simplify getSectionPiece

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 14:25:05 PST 2018


Author: maskray
Date: Tue Dec  4 14:25:05 2018
New Revision: 348311

URL: http://llvm.org/viewvc/llvm-project?rev=348311&view=rev
Log:
[ELF] Simplify getSectionPiece

Reviewers: ruiu, espindola

Reviewed By: ruiu

Subscribers: grimar, emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D55248

Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=348311&r1=348310&r2=348311&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Dec  4 14:25:05 2018
@@ -1223,18 +1223,11 @@ SectionPiece *MergeInputSection::getSect
 
   // If Offset is not at beginning of a section piece, it is not in the map.
   // In that case we need to  do a binary search of the original section piece vector.
-  size_t Size = Pieces.size();
-  size_t Idx = 0;
-
-  while (Size != 1) {
-    size_t H = Size / 2;
-    Size -= H;
-    if (Pieces[Idx + H].InputOff <= Offset)
-      Idx += H;
-  }
-  if (Offset < Pieces[Idx].InputOff)
-    --Idx;
-  return &Pieces[Idx];
+  auto It2 =
+      llvm::upper_bound(Pieces, Offset, [](uint64_t Offset, SectionPiece P) {
+        return Offset < P.InputOff;
+      });
+  return &It2[-1];
 }
 
 // Returns the offset in an output section for a given input offset.




More information about the llvm-commits mailing list