From f96c524375b5e0ce437f38b9dca294aafa45daa4 Mon Sep 17 00:00:00 2001 From: Joel Potter Date: Tue, 20 Feb 2024 08:26:40 -0500 Subject: [PATCH] Apply a hashset equals for performance --- Build/CommonAssemblyInfo.cs | 4 ++-- Griddly/Views/Shared/Griddly/Griddly.cshtml | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Build/CommonAssemblyInfo.cs b/Build/CommonAssemblyInfo.cs index de38d94..f264678 100644 --- a/Build/CommonAssemblyInfo.cs +++ b/Build/CommonAssemblyInfo.cs @@ -15,6 +15,6 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("3.7.1")] -[assembly: AssemblyFileVersion("3.7.1")] +[assembly: AssemblyVersion("3.7.2")] +[assembly: AssemblyFileVersion("3.7.2")] //[assembly: AssemblyInformationalVersion("2.5-filters")] diff --git a/Griddly/Views/Shared/Griddly/Griddly.cshtml b/Griddly/Views/Shared/Griddly/Griddly.cshtml index d1fb639..4bfb8a3 100644 --- a/Griddly/Views/Shared/Griddly/Griddly.cshtml +++ b/Griddly/Views/Shared/Griddly/Griddly.cshtml @@ -120,10 +120,20 @@ if (param != null) { - // TODO: perhaps use hashset for performance or a scrambled equals algo? - // https://stackoverflow.com/a/3670008/65611 - // https://stackoverflow.com/a/3670089/65611 - return Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(x.Value)?.OrderBy(y => y).SequenceEqual(Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(param).OrderBy(y => y)) ?? false; + // se hashset for performance https://stackoverflow.com/a/3670008/65611 + // if duplicate values are desirable (I can't think of why) we can switch to a a scrambled equals: https://stackoverflow.com/a/3670089/65611 + //return Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(x.Value)?.OrderBy(y => y).SequenceEqual(Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(param).OrderBy(y => y)) ?? false; + + var vals = Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(x.Value); + + if (vals == null) + { + return false; + } + + var parms = Griddly.Mvc.GriddlyExtensions.GetFormattedValueByType(param); + + return new HashSet(vals).SetEquals(new HashSet(parms)); } return false;