Statically cache item type names to avoid slowdowns

This commit is contained in:
Matt Nadareski
2026-04-05 11:15:07 -04:00
parent f93d254a64
commit d8e4f963c0
2 changed files with 7 additions and 5 deletions

View File

@@ -18,6 +18,11 @@ namespace SabreTools.Metadata.Filter
/// </summary>
public readonly string FieldName;
/// <summary>
/// Cached item type names for filter selection
/// </summary>
private static readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames();
/// <summary>
/// Validating combined key constructor
/// </summary>
@@ -149,12 +154,9 @@ namespace SabreTools.Metadata.Filter
if (string.Equals(itemName, "datitem", StringComparison.OrdinalIgnoreCase)
|| string.Equals(itemName, "item", StringComparison.OrdinalIgnoreCase))
{
// Get all item types
var itemTypes = TypeHelper.GetDatItemTypeNames();
// If we get any matches
string localFieldName = fieldName;
string? matchedType = Array.Find(itemTypes, t => DatItemContainsField(t, localFieldName));
string? matchedType = Array.Find(_datItemTypeNames, t => DatItemContainsField(t, localFieldName));
if (matchedType is not null)
{
// Check for a matching field

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Metadata.Filter
/// <summary>
/// Cached item type names for filter selection
/// </summary>
private readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames();
private static readonly string[] _datItemTypeNames = TypeHelper.GetDatItemTypeNames();
public FilterRunner(FilterObject[] filters)
{