Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more types (Dictionary etc) #10

Open
kamyker opened this issue Jan 16, 2023 · 1 comment
Open

Add more types (Dictionary etc) #10

kamyker opened this issue Jan 16, 2023 · 1 comment

Comments

@kamyker
Copy link

kamyker commented Jan 16, 2023

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.

@WhiteBlackGoose
Copy link
Member

Nice! Would you mind making a PR or at least a patch?

@kamyker kamyker changed the title Add more types (HashSet etc) Add more types (Dictionary etc) Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants