1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

Avoid allocating CarouselItems for bounds checks

This commit is contained in:
Dean Herbert 2020-10-13 18:33:31 +09:00
parent 4f4f222514
commit 40a0ab7aaa

View File

@ -646,19 +646,24 @@ namespace osu.Game.Screens.Select
}
}
private readonly CarouselBoundsItem carouselBoundsItem = new CarouselBoundsItem();
private (int firstIndex, int lastIndex) getDisplayRange()
{
// Find index range of all items that should be on-screen
// TODO: reduce allocs of CarouselBoundsItem.
int firstIndex = visibleItems.BinarySearch(new CarouselBoundsItem(visibleUpperBound - distance_offscreen_to_preload));
carouselBoundsItem.CarouselYPosition = visibleUpperBound - distance_offscreen_to_preload;
int firstIndex = visibleItems.BinarySearch(carouselBoundsItem);
if (firstIndex < 0) firstIndex = ~firstIndex;
int lastIndex = visibleItems.BinarySearch(new CarouselBoundsItem(visibleBottomBound + distance_offscreen_to_preload));
carouselBoundsItem.CarouselYPosition = visibleBottomBound + distance_offscreen_to_preload;
int lastIndex = visibleItems.BinarySearch(carouselBoundsItem);
if (lastIndex < 0) lastIndex = ~lastIndex;
// as we can't be 100% sure on the size of individual carousel drawables,
// always play it safe and extend bounds by one.
firstIndex = Math.Max(0, firstIndex - 1);
lastIndex = Math.Min(visibleItems.Count, lastIndex + 1);
return (firstIndex, lastIndex);
}
@ -856,11 +861,6 @@ namespace osu.Game.Screens.Select
/// </summary>
private class CarouselBoundsItem : CarouselItem
{
public CarouselBoundsItem(in float pos)
{
CarouselYPosition = pos;
}
public override DrawableCarouselItem CreateDrawableRepresentation() =>
throw new NotImplementedException();
}