Skip to content

Add more types (Dictionary etc) #10

@kamyker

Description

@kamyker

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions