1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Merge pull request #15736 from peppy/ruleset-use-short-name

Use `Ruleset`'s `ShortName` for mod caching purposes
This commit is contained in:
Bartłomiej Dach 2021-11-22 21:37:45 +01:00 committed by GitHub
commit d9db3b9e78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,7 +39,7 @@ namespace osu.Game.Rulesets
{
public RulesetInfo RulesetInfo { get; internal set; }
private static readonly ConcurrentDictionary<int, IMod[]> mod_reference_cache = new ConcurrentDictionary<int, IMod[]>();
private static readonly ConcurrentDictionary<string, IMod[]> mod_reference_cache = new ConcurrentDictionary<string, IMod[]>();
/// <summary>
/// A queryable source containing all available mods.
@ -49,11 +49,12 @@ namespace osu.Game.Rulesets
{
get
{
if (!(RulesetInfo.ID is int id))
// Is the case for many test usages.
if (string.IsNullOrEmpty(ShortName))
return CreateAllMods();
if (!mod_reference_cache.TryGetValue(id, out var mods))
mod_reference_cache[id] = mods = CreateAllMods().Cast<IMod>().ToArray();
if (!mod_reference_cache.TryGetValue(ShortName, out var mods))
mod_reference_cache[ShortName] = mods = CreateAllMods().Cast<IMod>().ToArray();
return mods;
}