Skip to content

ImmutableHashSet<T>.SetEquals always creates a new HashSet<T> #90986

Open
@sharwell

Description

@sharwell

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);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions