perf: Potential performance improvement when comparing enumerables

This commit is contained in:
Chris Cameron
2018-10-30 13:47:08 -04:00
parent 6eacc21e45
commit 03de74a494

View File

@@ -227,6 +227,12 @@ namespace ICD.Common.Utils.Extensions
if (comparer == null)
throw new ArgumentNullException("comparer");
// Simple count check
ICollection<T> a = extends as ICollection<T>;
ICollection<T> b = other as ICollection<T>;
if (a != null && b != null && a.Count != b.Count)
return false;
using (IEnumerator<T> firstPos = extends.GetEnumerator())
{
using (IEnumerator<T> secondPos = other.GetEnumerator())
@@ -285,6 +291,12 @@ namespace ICD.Common.Utils.Extensions
if (comparer == null)
throw new ArgumentNullException("comparer");
// Simple count check
ICollection<T> a = extends as ICollection<T>;
ICollection<T> b = other as ICollection<T>;
if (a != null && b != null && a.Count != b.Count)
return false;
Dictionary<T, int> count = new Dictionary<T, int>(comparer);
foreach (T item in extends)