[ELF] Simplify getSectionPiece
Reviewers: ruiu, espindola
Reviewed By: ruiu
Subscribers: grimar, emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D55248
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@348311 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/ELF/InputSection.cpp b/ELF/InputSection.cpp
index 38654d5..97df033 100644
--- a/ELF/InputSection.cpp
+++ b/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.