Add ConcurrentDictionary GetOrAdd/AddOrUpdate overloads with generic arg#1783
Add ConcurrentDictionary GetOrAdd/AddOrUpdate overloads with generic arg#1783stephentoub merged 1 commit intodotnet:futurefrom
Conversation
|
cc: @justinvp, @AlfredoMS, @terrajobst |
|
@stephentoub, thanks for putting this together!
I agree; I'm good with just the single new overload for Question: Is there a need for separate Minor naming question: |
Yeah, that was my reasoning as well (that, and if you really need different args you can package them up into a struct, and then just pay the copying cost of the one that isn't needed).
No strong preference, either. @KrzysztofCwalina, suggestions? |
|
@dotnet-bot test this please |
|
I agree that factoryArgument would be better. I think it clarifies what the argument is for. |
|
Thanks, guys; fixed the new parameter's name. |
|
@dotnet-bot test this please |
|
nit: |
|
Oh, ok. |
253275e to
8d39c40
Compare
|
Let's try that again ;) |
There was a problem hiding this comment.
Sorry I didn't catch this earlier, but should this be TryUpdateInternal to reuse the once-computed hashcode?
There was a problem hiding this comment.
Yes, it should be. This was just copy-and-paste from the current overload, which highlights that it, too, is calling TryUpdate instead of TryUpdateInternal. I'll fix this one here, but submit a separate PR to master to fix the current overload.
There was a problem hiding this comment.
Fixed. And opened #1833 to address the existing TryUpdate calls.
Adds one overload to each of GetOrAdd and AddOrUpdate. These overloads accept a generic argument that is passed through to any invocations of the supplied delegates, enabling developers to avoid delegate/closure allocations when more input is needed than just the key or existing value. For AddOrUpdate, there are two existing overloads with delegates; this only provide a new overload for the one that accepts two delegates.
8d39c40 to
fffd49f
Compare
Add ConcurrentDictionary GetOrAdd/AddOrUpdate overloads with generic arg
Adds one overload to each of GetOrAdd and AddOrUpdate. These overloads accept a generic argument that is passed through to any invocations of the supplied delegates, enabling developers to avoid delegate/closure allocations when more input is needed than just the key or existing value. The implementations are exact copies of the existing overloads then augmented with the additional parameter and threading that through to the delegate invocations.
For AddOrUpdate, there are two existing overloads with delegates, and #394 proposes that a new overload be added for each. I went back and forth on that, and for now this PR only provide a new overload for the one that accepts two delegates, as the other just didn't seem worth it (to my recollection we also didn't discuss both of these overloads in the API review... I hadn't actually realized that a new overload was proposed for each of them). If folks feel like it's really important to have the third one, though, I can add it.
Fixes https://github.com/dotnet/corefx/issues/394.