From 0dec3b29259dad7a69443e52f131c501ee9b56d0 Mon Sep 17 00:00:00 2001 From: Andriy Tolstoy Date: Fri, 8 Mar 2024 11:37:20 +0100 Subject: [PATCH] simplify equality comparer --- ...nfigurationDictionaryEqualityComparer`2.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/Silverback.Core/Util/ConfigurationDictionaryEqualityComparer`2.cs b/src/Silverback.Core/Util/ConfigurationDictionaryEqualityComparer`2.cs index c05707a60..5c622c3c4 100644 --- a/src/Silverback.Core/Util/ConfigurationDictionaryEqualityComparer`2.cs +++ b/src/Silverback.Core/Util/ConfigurationDictionaryEqualityComparer`2.cs @@ -48,24 +48,9 @@ public bool Equals(IEnumerable>? x, IEnumerable pair.Key) - .Union(y.Select(pair => pair.Key)) - .Distinct() - .ToList(); + var hashY = y.ToDictionary(pair => pair.Key, pair => pair.Value); - if (allKeys.Count != x.Count()) - return false; - - foreach (var key in allKeys) - { - var valueX = x.FirstOrDefault(pair => Equals(pair.Key, key)); - var valueY = y.FirstOrDefault(pair => Equals(pair.Key, key)); - - if (!Equals(valueX, valueY)) - return false; - } - - return true; + return x.All(pairX => hashY.TryGetValue(pairX.Key, out var valueY) && Equals(pairX.Value, valueY)); } public int GetHashCode(IEnumerable> obj) => obj.Count();