mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Merge pull request #1300 from Caraxi/improveConfigPerformance
This commit is contained in:
commit
2cf3b93b64
1 changed files with 19 additions and 4 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using Dalamud.Utility;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
using Dalamud.Utility;
|
||||
|
||||
namespace Dalamud.Game.Config;
|
||||
|
||||
|
|
@ -7,6 +9,10 @@ namespace Dalamud.Game.Config;
|
|||
/// </summary>
|
||||
internal static class GameConfigEnumExtensions
|
||||
{
|
||||
private static readonly ConcurrentDictionary<SystemConfigOption, string> SystemNameCache = new();
|
||||
private static readonly ConcurrentDictionary<UiConfigOption, string> UIConfigNameCache = new();
|
||||
private static readonly ConcurrentDictionary<UiControlOption, string> UIControlNameCache = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of a SystemConfigOption from it's attribute.
|
||||
/// </summary>
|
||||
|
|
@ -14,7 +20,10 @@ internal static class GameConfigEnumExtensions
|
|||
/// <returns>Name of the option.</returns>
|
||||
public static string GetName(this SystemConfigOption systemConfigOption)
|
||||
{
|
||||
return systemConfigOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{systemConfigOption}";
|
||||
if (SystemNameCache.TryGetValue(systemConfigOption, out var name)) return name;
|
||||
name = systemConfigOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{systemConfigOption}";
|
||||
SystemNameCache.TryAdd(systemConfigOption, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -24,7 +33,10 @@ internal static class GameConfigEnumExtensions
|
|||
/// <returns>Name of the option.</returns>
|
||||
public static string GetName(this UiConfigOption uiConfigOption)
|
||||
{
|
||||
return uiConfigOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{uiConfigOption}";
|
||||
if (UIConfigNameCache.TryGetValue(uiConfigOption, out var name)) return name;
|
||||
name = uiConfigOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{uiConfigOption}";
|
||||
UIConfigNameCache.TryAdd(uiConfigOption, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -34,6 +46,9 @@ internal static class GameConfigEnumExtensions
|
|||
/// <returns>Name of the option.</returns>
|
||||
public static string GetName(this UiControlOption uiControlOption)
|
||||
{
|
||||
return uiControlOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{uiControlOption}";
|
||||
if (UIControlNameCache.TryGetValue(uiControlOption, out var name)) return name;
|
||||
name = uiControlOption.GetAttribute<GameConfigOptionAttribute>()?.Name ?? $"{uiControlOption}";
|
||||
UIControlNameCache.TryAdd(uiControlOption, name);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue