mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 09:17:51 +08:00
Redice allocations during aggregate beatmap sort
This commit is contained in:
parent
c588b81cee
commit
6e1b4152c0
@ -127,12 +127,40 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// All beatmaps which are not filtered and valid for display.
|
/// All beatmaps which are not filtered and valid for display.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected IEnumerable<BeatmapInfo> ValidBeatmaps => Beatmaps.Where(b => !b.Filtered.Value || b.State.Value == CarouselItemState.Selected).Select(b => b.BeatmapInfo);
|
protected IEnumerable<BeatmapInfo> ValidBeatmaps
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (var item in Items) // iterating over Items directly to not allocate 2 enumerators
|
||||||
|
{
|
||||||
|
if (item is CarouselBeatmap b && (!b.Filtered.Value || b.State.Value == CarouselItemState.Selected))
|
||||||
|
yield return b.BeatmapInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether there are available beatmaps which are not filtered and valid for display.
|
||||||
|
/// Cheaper alternative to <see cref="ValidBeatmaps"/>.Any()
|
||||||
|
/// </summary>
|
||||||
|
public bool HasValidBeatmaps
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (var item in Items) // iterating over Items directly to not allocate 2 enumerators
|
||||||
|
{
|
||||||
|
if (item is CarouselBeatmap b && (!b.Filtered.Value || b.State.Value == CarouselItemState.Selected))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int compareUsingAggregateMax(CarouselBeatmapSet other, Func<BeatmapInfo, double> func)
|
private int compareUsingAggregateMax(CarouselBeatmapSet other, Func<BeatmapInfo, double> func)
|
||||||
{
|
{
|
||||||
bool ourBeatmaps = ValidBeatmaps.Any();
|
bool ourBeatmaps = HasValidBeatmaps;
|
||||||
bool otherBeatmaps = other.ValidBeatmaps.Any();
|
bool otherBeatmaps = other.HasValidBeatmaps;
|
||||||
|
|
||||||
if (!ourBeatmaps && !otherBeatmaps) return 0;
|
if (!ourBeatmaps && !otherBeatmaps) return 0;
|
||||||
if (!ourBeatmaps) return -1;
|
if (!ourBeatmaps) return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user