mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:43:21 +08:00
Avoid allocating CarouselItems for bounds checks
This commit is contained in:
parent
4f4f222514
commit
40a0ab7aaa
@ -646,19 +646,24 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly CarouselBoundsItem carouselBoundsItem = new CarouselBoundsItem();
|
||||||
|
|
||||||
private (int firstIndex, int lastIndex) getDisplayRange()
|
private (int firstIndex, int lastIndex) getDisplayRange()
|
||||||
{
|
{
|
||||||
// Find index range of all items that should be on-screen
|
// Find index range of all items that should be on-screen
|
||||||
// TODO: reduce allocs of CarouselBoundsItem.
|
carouselBoundsItem.CarouselYPosition = visibleUpperBound - distance_offscreen_to_preload;
|
||||||
int firstIndex = visibleItems.BinarySearch(new CarouselBoundsItem(visibleUpperBound - distance_offscreen_to_preload));
|
int firstIndex = visibleItems.BinarySearch(carouselBoundsItem);
|
||||||
if (firstIndex < 0) firstIndex = ~firstIndex;
|
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;
|
if (lastIndex < 0) lastIndex = ~lastIndex;
|
||||||
|
|
||||||
// as we can't be 100% sure on the size of individual carousel drawables,
|
// as we can't be 100% sure on the size of individual carousel drawables,
|
||||||
// always play it safe and extend bounds by one.
|
// always play it safe and extend bounds by one.
|
||||||
firstIndex = Math.Max(0, firstIndex - 1);
|
firstIndex = Math.Max(0, firstIndex - 1);
|
||||||
lastIndex = Math.Min(visibleItems.Count, lastIndex + 1);
|
lastIndex = Math.Min(visibleItems.Count, lastIndex + 1);
|
||||||
|
|
||||||
return (firstIndex, lastIndex);
|
return (firstIndex, lastIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -856,11 +861,6 @@ namespace osu.Game.Screens.Select
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private class CarouselBoundsItem : CarouselItem
|
private class CarouselBoundsItem : CarouselItem
|
||||||
{
|
{
|
||||||
public CarouselBoundsItem(in float pos)
|
|
||||||
{
|
|
||||||
CarouselYPosition = pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override DrawableCarouselItem CreateDrawableRepresentation() =>
|
public override DrawableCarouselItem CreateDrawableRepresentation() =>
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user