Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -375,24 +375,73 @@ public bool SetEquals(IEnumerable<T> other)
return true;
}

var otherSet = new SortedSet<T>(other, this.KeyComparer);
if (this.Count != otherSet.Count)
if (other is ICollection<T> otherAsICollection && otherAsICollection.Count < this.Count)
{
return false;
}

int matches = 0;
foreach (T item in otherSet)
else if (other is IReadOnlyCollection<T> otherAsIReadOnlyCollection && otherAsIReadOnlyCollection.Count < this.Count)
{
if (!this.Contains(item))
return false;
}

if (other is ImmutableSortedSet<T> otherAsImmutableSortedSet && otherAsImmutableSortedSet.KeyComparer == this.KeyComparer)
{
if (otherAsImmutableSortedSet.Count != this.Count)
{
return false;
}
using var otherAsImmutableSortedSetEnumerator = otherAsImmutableSortedSet.GetEnumerator();
using (var thisEnumerator = this.GetEnumerator())
{
while (otherAsImmutableSortedSetEnumerator.MoveNext() && thisEnumerator.MoveNext())
{
if (this.KeyComparer.Compare(otherAsImmutableSortedSetEnumerator.Current, thisEnumerator.Current) != 0)
{
return false;
}
}
}
return true;
}

matches++;
else if (other is SortedSet<T> otherAsSortedSet && otherAsSortedSet.Comparer == this.KeyComparer)
{
if (otherAsSortedSet.Count != this.Count)
{
return false;
}
using var otherAsSortedSetEnumerator = otherAsSortedSet.GetEnumerator();
using (var thisEnumerator = this.GetEnumerator())
{
while (otherAsSortedSetEnumerator.MoveNext() && thisEnumerator.MoveNext())
{
if (this.KeyComparer.Compare(otherAsSortedSetEnumerator.Current, thisEnumerator.Current) != 0)
{
return false;
}
}
}
return true;
}

return matches == this.Count;
var otherSet = new SortedSet<T>(other, this.KeyComparer);
if (this.Count != otherSet.Count)
{
return false;
}
using var otherSetEnumerator = otherSet.GetEnumerator();
using (var thisEnumerator = this.GetEnumerator())
{
while (otherSetEnumerator.MoveNext() && thisEnumerator.MoveNext())
{
if (this.KeyComparer.Compare(otherSetEnumerator.Current, thisEnumerator.Current) != 0)
{
return false;
}
}
}
return true;
}

/// <summary>
Expand Down
Loading