mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Statically cache item type names to avoid slowdowns
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user