[PATCH] D55248: [ELF] Simplify getSectionPiece

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 14:28:15 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD348311: [ELF] Simplify getSectionPiece (authored by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55248?vs=176709&id=176711#toc

Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55248/new/

https://reviews.llvm.org/D55248

Files:
  ELF/InputSection.cpp


Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -1223,18 +1223,11 @@
 
   // 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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55248.176711.patch
Type: text/x-patch
Size: 833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181204/5a8f60bd/attachment.bin>


More information about the llvm-commits mailing list