mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-26 17:46:26 +03:00
c86ce869c3
This PR replaces `Array.filter` calls in `SegmentIndex.merge()`,`mergeAndEvict()`, and `evict()` with more efficient alternatives. The key addition is `binarySearch` helper: it repeatedly checks the midpoint and discards half the array each time. The idea is the same as `Array.findIndex` but exploiting the sorted order to skip most of the work. `merge()` and `evict()` use this to find their truncation/expiry boundary; `mergeAndEvict()` uses a simple forward scan that stops at the first valid reference since stale refs are always bunched at the front. This is done to reduce iteration during playback (especially livestream with DVR) - no big new array creations by default - we don't create one when for example there is nothing to evict - fewer comparisons — binary search finds the cutoff without scanning the whole array - slice just copies the kept elements and that's it