From 6cb8f6091745fefd28cea0f13b97c035ab541fbd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 19 Mar 2024 14:10:51 -0400 Subject: [PATCH] Split IDDB filtering into a helper method --- SabreTools.DatFiles/ItemDictionaryDB.cs | 43 ++++++++++++++----------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/SabreTools.DatFiles/ItemDictionaryDB.cs b/SabreTools.DatFiles/ItemDictionaryDB.cs index 7c519c26..5e6c6ce7 100644 --- a/SabreTools.DatFiles/ItemDictionaryDB.cs +++ b/SabreTools.DatFiles/ItemDictionaryDB.cs @@ -858,25 +858,7 @@ namespace SabreTools.DatFiles foreach (var key in keys) #endif { - (long, DatItem)[]? items = GetDatItemsForBucket(key); - if (items == null) -#if NET40_OR_GREATER || NETCOREAPP - return; -#else - continue; -#endif - - // Filter all items in the current key - var newItems = new ConcurrentList<(long, DatItem)>(); - foreach (var item in items) - { - if (item.Item2.PassesFilter(filterRunner)) - newItems.Add(item); - } - - // Set the value in the key to the new set - _buckets[key] = newItems.Select(i => i.Item1).ToConcurrentList(); - + ExecuteFilterOnBucket(filterRunner, key); #if NET40_OR_GREATER || NETCOREAPP }); #else @@ -884,6 +866,29 @@ namespace SabreTools.DatFiles #endif } + /// + /// Execute all filters in a filter runner on a single bucket + /// + /// Preconfigured filter runner to use + /// Name of the bucket to filter on + private void ExecuteFilterOnBucket(FilterRunner filterRunner, string bucketName) + { + (long, DatItem)[]? items = GetDatItemsForBucket(bucketName); + if (items == null) + return; + + // Filter all items in the current key + var newItems = new ConcurrentList<(long, DatItem)>(); + foreach (var item in items) + { + if (item.Item2.PassesFilter(filterRunner)) + newItems.Add(item); + } + + // Set the value in the key to the new set + _buckets[bucketName] = newItems.Select(i => i.Item1).ToConcurrentList(); + } + #endregion #region Statistics