-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Just tried this and seems to not allocate in Unity. Something more generic like IReadOnlyCollection can't be used as it allocates.
public static RefLinqEnumerable<T, HashSetEnumerator<T>> ToRefLinq<T>(this HashSet<T> c) => new(new(c));
public struct HashSetEnumerator<T> : IRefEnumerable<T>
{
private T curr;
private HashSet<T>.Enumerator ie;
public HashSetEnumerator(HashSet<T> list)
{
ie = list.GetEnumerator();
curr = default;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool MoveNext()
{
bool end = ie.MoveNext();
curr = ie.Current;
if(!end)
ie.Dispose();
return end;
}
public T Current => curr;
}
No idea if that Dispose is correct.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels