Cache reflection calls when running utility lints and commands.

Reduces runtime of --check-yaml command to 70% of original.
This commit is contained in:
RoosterDragon
2023-03-28 19:04:14 +01:00
committed by Matthias Mailänder
parent 1a2aafa17c
commit 9dd4f938da
24 changed files with 116 additions and 87 deletions

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Lint
// Build the list of widget keys to validate
var checkWidgetFields = modData.ObjectCreator.GetTypesImplementing<Widget>()
.SelectMany(w => w.GetFields()
.SelectMany(w => Utility.GetFields(w)
.Where(f => f.FieldType == typeof(HotkeyReference))
.Select(f => (w.Name.Substring(0, w.Name.Length - 6), f.Name)))
.ToArray();
@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Lint
foreach (var w in modData.ObjectCreator.GetTypesImplementing<Widget>())
{
foreach (var m in w.GetMethods().Where(m => m.HasAttribute<CustomLintableHotkeyNames>()))
foreach (var m in w.GetMethods().Where(m => Utility.HasAttribute<CustomLintableHotkeyNames>(m)))
{
var p = m.GetParameters();
if (p.Length == 3 && p[0].ParameterType == typeof(MiniYamlNode) && p[1].ParameterType == typeof(Action<string>)
@@ -104,7 +104,7 @@ namespace OpenRA.Mods.Common.Lint
if (type == null)
continue;
checkArgKeys.AddRange(type.GetCustomAttributes<ChromeLogicArgsHotkeys>(true).SelectMany(x => x.LogicArgKeys));
checkArgKeys.AddRange(Utility.GetCustomAttributes<ChromeLogicArgsHotkeys>(type, true).SelectMany(x => x.LogicArgKeys));
}
foreach (var n in node.Value.Nodes)