The following HashSet<T> calculation could be avoided by using other.WithComparer(origin.KeyComparer) in the specific case where other is already an ImmutableHashSet<T>. It might also be avoidable in the case where other is already a HashSet<T> with an appropriate comparer.
Note that in addition to the overhead of performing these checks at runtime, there may be overhead added by the fact that ImmutableHashSet<T> has a slower enumerator than HashSet<T>, and the newly allocated set is immediately enumerated.
|
var otherSet = new HashSet<T>(other, origin.EqualityComparer); |
The following
HashSet<T>calculation could be avoided by usingother.WithComparer(origin.KeyComparer)in the specific case whereotheris already anImmutableHashSet<T>. It might also be avoidable in the case whereotheris already aHashSet<T>with an appropriate comparer.Note that in addition to the overhead of performing these checks at runtime, there may be overhead added by the fact that
ImmutableHashSet<T>has a slower enumerator thanHashSet<T>, and the newly allocated set is immediately enumerated.runtime/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.cs
Line 758 in 7edfbc7