From 03de74a49450f882990b9145637574bb9b192052 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 30 Oct 2018 13:47:08 -0400 Subject: [PATCH] perf: Potential performance improvement when comparing enumerables --- ICD.Common.Utils/Extensions/EnumerableExtensions.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ICD.Common.Utils/Extensions/EnumerableExtensions.cs b/ICD.Common.Utils/Extensions/EnumerableExtensions.cs index 1d1269b..edac918 100644 --- a/ICD.Common.Utils/Extensions/EnumerableExtensions.cs +++ b/ICD.Common.Utils/Extensions/EnumerableExtensions.cs @@ -227,6 +227,12 @@ namespace ICD.Common.Utils.Extensions if (comparer == null) throw new ArgumentNullException("comparer"); + // Simple count check + ICollection a = extends as ICollection; + ICollection b = other as ICollection; + if (a != null && b != null && a.Count != b.Count) + return false; + using (IEnumerator firstPos = extends.GetEnumerator()) { using (IEnumerator secondPos = other.GetEnumerator()) @@ -285,6 +291,12 @@ namespace ICD.Common.Utils.Extensions if (comparer == null) throw new ArgumentNullException("comparer"); + // Simple count check + ICollection a = extends as ICollection; + ICollection b = other as ICollection; + if (a != null && b != null && a.Count != b.Count) + return false; + Dictionary count = new Dictionary(comparer); foreach (T item in extends)