HonkPerf.NET icon indicating copy to clipboard operation
HonkPerf.NET copied to clipboard

Add more types (Dictionary etc)

Open kamyker opened this issue 1 year ago • 1 comments

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.

kamyker avatar Jan 16 '23 07:01 kamyker