-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
reflect: rename MapIter.SetKey/SetValue -> Value.SetIterKey/SetIterValue #48294
Comments
Or even,
? |
I like that even better :) |
Although, you probably want to add func (v Value) SetMapKey(it *MapIter)
func (v Value) SetMapValue(it *MapIter) since the other map functionality have |
Or |
I was looking at sources of allocations using v.Set(m.MapIndex(k)) Ideally, we would be able to do this with an allocation-free API. Perhaps: v.SetMapIndex(m, k) Whatever names we chose here, I would hope that it doesn't steal a good name from this possible API. |
This proposal has been added to the active column of the proposals project |
The proposal seems to be to rename the functions so that
Is that right? Is there some kind of trick we can do in v.Set to enable these kinds of optimizations invisibly? |
That would be ideal. #48000 is the same class of problem with a similar proposed solution. |
I'm not sure we can, as I guess the compiler could have a special case for |
If the part of |
|
In order to avoid a copy, we need to know that no map write operation happens between |
Thanks for the discussion about optimizations. It does seem like SetIterKey and SetIterValue are the way to go. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://golang.org/cl/356049 mentions this issue: |
Change https://golang.org/cl/356050 mentions this issue: |
Update #48294 Update #47694 Change-Id: I4d4c01be74a9736d89a4ec92318ce29ff7289a0d Reviewed-on: https://go-review.googlesource.com/c/go/+/356050 Trust: Keith Randall <khr@golang.org> Reviewed-by: Joe Tsai <joetsai@digital-static.net>
(copying my comment from #46131 (comment) to avoid it being forgotten for the 1.18 release)
Bikeshed: I was a little confused by the direction of setting. In
reflect
, we have:All of these store a value into the receiver
v
from the input argument.Now we added:
However, contrary to
reflect.Value.SetXXX
, a value is being stored into the input argument from state in the receiverit
. It is the opposite direction.Perhaps we should rename it as
SetKeyInto
andSetValueInto
? OrStoreKey
andStoreValue
(per @josharian's suggestion)?\cc @rsc @randall77
The text was updated successfully, but these errors were encountered: