-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add TryAdd and TryGetValue overloads with out int index to OrderedDictionary
#109324
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 TryAdd and TryGetValue overloads with out int index to OrderedDictionary
#109324
Conversation
|
Note regarding the |
1 similar comment
|
Note regarding the |
out var index to OrderedDictionaryout int index to OrderedDictionary
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Collections/src/System/Collections/Generic/OrderedDictionary.cs
Show resolved
Hide resolved
...raries/System.Collections/tests/Generic/OrderedDictionary/OrderedDictionary.Generic.Tests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs
Outdated
Show resolved
Hide resolved
| OrderedDictionary<string, JsonNode?> dict = Dictionary; | ||
|
|
||
| if (!dict.TryAdd(propertyName, value)) | ||
| if (!dict.TryAdd(propertyName, value, out int index)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting the CI build error locally as well. I think the issue is that .net 9.0 doesn't have the new TryAdd(..., out int index) method (the failure indicates that the S.T.J. build for 9.0 is causing the error). Should I be ifdefing here to check for that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ifdefing is fine. The alternative would be to polyfill the current version of OrderedDictionary for net9.0 as we do with the older targets, but I don't think this change is worth the duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the style we use for #ifs but I wanted to avoid having the #if region cross into the if block.
eiriktsarpalis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great work as usual!
|
@PranavSenthilnathan should we get this merged? |
|
Added perf numbers to my first comment. Around 10-20% improvement for adding and updating in JsonObject (this PR improves the updating part of the scenario). |
Fixes #107947 and #107944
Adds and consumes the following API:
Perf Impact:
Expand for code