From 0b189e17f88f171e867a45dde48efbc7f9cb22aa Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Sat, 15 Jul 2017 18:10:15 +0000 Subject: [PATCH] Fix mis-use of std::lower_bound Binary search in C++ is such a PITA. =/ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@308106 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/BinaryItemStream.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/llvm/Support/BinaryItemStream.h b/include/llvm/Support/BinaryItemStream.h index 8325a85af8d..fe7e6caeaaf 100644 --- a/include/llvm/Support/BinaryItemStream.h +++ b/include/llvm/Support/BinaryItemStream.h @@ -88,9 +88,9 @@ private: // Make sure the offset is somewhere in our items array. if (Offset >= getLength()) return make_error(stream_error_code::stream_too_short); - auto Iter = std::lower_bound( - ItemEndOffsets.begin(), ItemEndOffsets.end(), Offset, - [](const uint32_t &A, const uint32_t &B) { return A <= B; }); + ++Offset; + auto Iter = + std::lower_bound(ItemEndOffsets.begin(), ItemEndOffsets.end(), Offset); size_t Idx = std::distance(ItemEndOffsets.begin(), Iter); assert(Idx < Items.size() && "binary search for offset failed"); return Idx; -- 2.49.0