1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 19:12:56 +02:00

Fix mis-use of std::lower_bound

Binary search in C++ is such a PITA. =/

llvm-svn: 308106
This commit is contained in:
Reid Kleckner 2017-07-15 18:10:15 +00:00
parent 122bdff7b3
commit e88825c163

View File

@ -88,9 +88,9 @@ private:
// Make sure the offset is somewhere in our items array.
if (Offset >= getLength())
return make_error<BinaryStreamError>(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;