mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
perf: Potential performance improvement when comparing enumerables
This commit is contained in:
@@ -227,6 +227,12 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
if (comparer == null)
|
if (comparer == null)
|
||||||
throw new ArgumentNullException("comparer");
|
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> firstPos = extends.GetEnumerator())
|
||||||
{
|
{
|
||||||
using (IEnumerator<T> secondPos = other.GetEnumerator())
|
using (IEnumerator<T> secondPos = other.GetEnumerator())
|
||||||
@@ -285,6 +291,12 @@ namespace ICD.Common.Utils.Extensions
|
|||||||
if (comparer == null)
|
if (comparer == null)
|
||||||
throw new ArgumentNullException("comparer");
|
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);
|
Dictionary<T, int> count = new Dictionary<T, int>(comparer);
|
||||||
|
|
||||||
foreach (T item in extends)
|
foreach (T item in extends)
|
||||||
|
|||||||
Reference in New Issue
Block a user