-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: reflect: add Value.SetMapIndexOf #57061
Comments
Does the same also hold for the |
Are there any other existing |
Some of the notable operations that may allocate unnecessarily are:
Most of these all have a modern workaround that are more performant:
|
I'm not a big fan of the |
For alternative APIs, one could imagine:
But it's not clear to me that any of those are less warty than the proposed |
For most reflection operation, there is an allocation free way to walk a value tree. At present, there is no way to obtain the value of a map entry without allocating since
reflect.Value.MapIndex
allocates the underlying value on the heap (since map entries are unaddressable).Assuming we can't do #57060, I propose an explicit API for setting an addressable value with the value of a map entry:
The method is so named because the
SetMapIndex
method is already taken up for the operation equivalent tov[key] = elem
. Alternative suggest names welcome.The text was updated successfully, but these errors were encountered: