Merge pull request #18619 from peppy/fix-collection-performance

Fix performance overhead of large collections
This commit is contained in:
Dan Balasescu
2022-06-10 15:01:31 +09:00
committed by GitHub
13 changed files with 59 additions and 50 deletions

View File

@ -72,7 +72,7 @@ namespace osu.Game.Screens.Select.Carousel
}
if (match)
match &= criteria.Collection?.Beatmaps.Contains(BeatmapInfo) ?? true;
match &= criteria.Collection?.BeatmapHashes.Contains(BeatmapInfo.MD5Hash) ?? true;
if (match && criteria.RulesetCriteria != null)
match &= criteria.RulesetCriteria.Matches(BeatmapInfo);

View File

@ -256,12 +256,12 @@ namespace osu.Game.Screens.Select.Carousel
return new ToggleMenuItem(collection.Name.Value, MenuItemType.Standard, s =>
{
if (s)
collection.Beatmaps.Add(beatmapInfo);
collection.BeatmapHashes.Add(beatmapInfo.MD5Hash);
else
collection.Beatmaps.Remove(beatmapInfo);
collection.BeatmapHashes.Remove(beatmapInfo.MD5Hash);
})
{
State = { Value = collection.Beatmaps.Contains(beatmapInfo) }
State = { Value = collection.BeatmapHashes.Contains(beatmapInfo.MD5Hash) }
};
}

View File

@ -245,7 +245,7 @@ namespace osu.Game.Screens.Select.Carousel
TernaryState state;
int countExisting = beatmapSet.Beatmaps.Count(b => collection.Beatmaps.Contains(b));
int countExisting = beatmapSet.Beatmaps.Count(b => collection.BeatmapHashes.Contains(b.MD5Hash));
if (countExisting == beatmapSet.Beatmaps.Count)
state = TernaryState.True;
@ -261,14 +261,14 @@ namespace osu.Game.Screens.Select.Carousel
switch (s)
{
case TernaryState.True:
if (collection.Beatmaps.Contains(b))
if (collection.BeatmapHashes.Contains(b.MD5Hash))
continue;
collection.Beatmaps.Add(b);
collection.BeatmapHashes.Add(b.MD5Hash);
break;
case TernaryState.False:
collection.Beatmaps.Remove(b);
collection.BeatmapHashes.Remove(b.MD5Hash);
break;
}
}