1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:43:22 +08:00

Avoid sorting items when already in the correct sort order

This commit is contained in:
Dean Herbert 2023-12-05 14:15:05 +09:00
parent 7fda38d0b0
commit 27e778ae09
No known key found for this signature in database

View File

@ -86,16 +86,20 @@ namespace osu.Game.Screens.Select.Carousel
items.ForEach(c => c.Filter(criteria));
criteriaComparer = Comparer<CarouselItem>.Create((x, y) =>
// Sorting is expensive, so only perform if it's actually changed.
if (lastCriteria?.Sort != criteria.Sort)
{
int comparison = x.CompareTo(criteria, y);
if (comparison != 0)
return comparison;
criteriaComparer = Comparer<CarouselItem>.Create((x, y) =>
{
int comparison = x.CompareTo(criteria, y);
if (comparison != 0)
return comparison;
return x.ItemID.CompareTo(y.ItemID);
});
return x.ItemID.CompareTo(y.ItemID);
});
items.Sort(criteriaComparer);
items.Sort(criteriaComparer);
}
lastCriteria = criteria;
}