mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-04-12 12:07:05 +00:00
perf: Potential performance improvement when comparing enumerables
This commit is contained in:
parent
6eacc21e45
commit
03de74a494
1 changed files with 12 additions and 0 deletions
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue