lottie: ++binary search stability.

this ensures that the return value is not below 0,
when the frame count is just 2.
This commit is contained in:
Hermet Park 2024-04-16 12:18:45 +09:00
parent 9e6a837125
commit 5a8e15aebd

View file

@ -195,17 +195,18 @@ struct LottieVectorFrame
template<typename T> template<typename T>
uint32_t bsearch(T* frames, float frameNo) uint32_t bsearch(T* frames, float frameNo)
{ {
uint32_t low = 0; int32_t low = 0;
uint32_t high = frames->count - 1; int32_t high = int32_t(frames->count) - 1;
while (low <= high) { while (low <= high) {
auto mid = low + (high - low) / 2; auto mid = low + (high - low) / 2;
auto frame = frames->data + mid; auto frame = frames->data + mid;
if (mathEqual(frameNo, frame->no)) return mid; if (frameNo < frame->no) high = mid - 1;
else if (frameNo < frame->no) high = mid - 1;
else low = mid + 1; else low = mid + 1;
} }
if (high < low) low = high; if (high < low) low = high;
if (low < 0) low = 0;
return low; return low;
} }