-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Howto implement HashSet.GetOrAdd(T) extension method in .NET 6 or .NET 7 using CollectionsMarshal #82875
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsHello.
but without a duplicate hash lookup (performance impact). That issue was closed with the following resolution:
In issue #15059 the last comment has an example of CollectionsMarshal usage for a Dictionary:
I've tried to use the same approach to implement HashSet.GetOrAdd(T) extention but failed - I don't have any idea how to get key value for CollectionsMarshal.GetValueRefOrAddDefault() method.
|
Adding |
How common is it that you need to have access to the precise instance stored by the We generally try to avoid adding new instance methods to very common generic types like |
@eiriktsarpalis I think that it is pretty rare. It is similar to searching a On the other hand the original proposal is closed with a comment that gives the impression that the |
Added a comment in the original issue for posterity. To answer the original question in this issue, I would recommend just using |
Hello.
On dotnet runtime Github repo there was a proposal for adding HashSet.GetOrAdd(T) - similar to
but without a duplicate hash lookup (performance impact). That issue was closed with the following resolution:
In issue #15059 the last comment has an example of CollectionsMarshal usage for a Dictionary:
I've tried to use the same approach to implement HashSet.GetOrAdd(T) extention but failed - I don't have any idea how to get key value for CollectionsMarshal.GetValueRefOrAddDefault() method.
Both issues are locked as resolved and limited to collaborators - so I cannot ask directly there.
Help me please. Thank you.
The text was updated successfully, but these errors were encountered: