[PATCH] D55248: [ELF] Simplify getSectionPiece

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 13:30:45 PST 2018


ruiu added a comment.

Yeah, I think with an optimizing compiler you cannot see any difference between the old and the new code.



================
Comment at: ELF/InputSection.cpp:1226
   // 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];
+  size_t I = upper_bound(Pieces, Offset, [](uint64_t Offset, SectionPiece P) {
+    return Offset < P.InputOff;
----------------
ruiu wrote:
> Calculating a distance between two iterators to use it as an array access index seems a bit awkward.
Can you add `llvm::` to `upper_bound` so that that looks obviously different from `std::upper_bound`?


================
Comment at: ELF/InputSection.cpp:1226-1228
+  size_t I = upper_bound(Pieces, Offset, [](uint64_t Offset, SectionPiece P) {
+    return Offset < P.InputOff;
+  }) - Pieces.begin();
----------------
Calculating a distance between two iterators to use it as an array access index seems a bit awkward.


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D55248





More information about the llvm-commits mailing list