mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 20:23:00 +08:00
Cache reflection portion of SettingSource
lookups
Fixes the mod-related overhead portion of https://github.com/ppy/osu/issues/14638. There's still a significant performance issue that will be addressed separately.
This commit is contained in:
parent
2c6ee0ebf7
commit
81c9d831f4
@ -167,18 +167,7 @@ namespace osu.Game.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourceProperties(this object obj)
|
||||
{
|
||||
foreach (var property in obj.GetType().GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance))
|
||||
{
|
||||
var attr = property.GetCustomAttribute<SettingSourceAttribute>(true);
|
||||
|
||||
if (attr == null)
|
||||
continue;
|
||||
|
||||
yield return (attr, property);
|
||||
}
|
||||
}
|
||||
public static IEnumerable<(SettingSourceAttribute, PropertyInfo)> GetSettingsSourceProperties<T>(this T obj) => SettingSourceCache<T>.SettingSourceProperties;
|
||||
|
||||
public static ICollection<(SettingSourceAttribute, PropertyInfo)> GetOrderedSettingsSourceProperties(this object obj)
|
||||
=> obj.GetSettingsSourceProperties()
|
||||
@ -196,5 +185,14 @@ namespace osu.Game.Configuration
|
||||
protected override DropdownMenu CreateMenu() => base.CreateMenu().With(m => m.MaxHeight = 100);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SettingSourceCache<T>
|
||||
{
|
||||
public static (SettingSourceAttribute, PropertyInfo)[] SettingSourceProperties { get; } =
|
||||
typeof(T).GetProperties(BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance)
|
||||
.Select(property => (property.GetCustomAttribute<SettingSourceAttribute>(), property))
|
||||
.Where(pair => pair.Item1 != null)
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user