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

Implement 'ConditionalWeakTable<TKey,TValue>.GetOrAdd' APIs #111204

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Sergio0694
Copy link
Contributor

Closes #89002

This PR implements the new APIs for ConditionalWeakTable<TKey, TValue> and hides some legacy ones:

namespace System.Runtime.CompilerServices;

public sealed partial class ConditionalWeakTable<TKey, TValue>
{
+   public TValue GetOrAdd(TKey key, TValue value);
+   public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory);
+   public TValue GetOrAdd<TArg>(TKey key, Func<TKey, TArg, TValue> valueFactory, TArg factoryArgument)
+       where TArg : allows ref struct;
    
+   [EditorBrowsable(EditorBrowsableState.Never)]
    public TValue GetValue(TKey key, CreateValueCallback createValueCallback);
  
+   [EditorBrowsable(EditorBrowsableState.Never)]
    public TValue GetOrCreateValue(TKey key);

+   [EditorBrowsable(EditorBrowsableState.Never)]
    public delegate TValue CreateValueCallback(TKey key);
}

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 8, 2025
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 10.0.0 milestone Jan 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • src/libraries/System.Runtime/ref/System.Runtime.cs: Evaluated as low risk

@jkotas
Copy link
Member

jkotas commented Jan 8, 2025

Go over Corelib and maybe other core assemblies and switch them to use the new API where appropriate? There are not that many candidates.

@Sergio0694
Copy link
Contributor Author

I've gone over uses I could find of the now hidden methods and replaced them. Particularly happy with how ComWrappers on Native AOT looks now, it could drop a couple of extra lookups entirely. @jkoritzinsky can you help take a look? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: ConditionalWeakTable<TKey,TValue>.GetOrAdd
6 participants