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:
// SetMapIndexOf is equivalent to v.Set(m.MapIndex(k)).
func (v Value) SetMapIndexOf(m, k Value)
The method is so named because the SetMapIndex method is already taken up for the operation equivalent to v[key] = elem. Alternative suggest names welcome.
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.MapIndexallocates 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
SetMapIndexmethod is already taken up for the operation equivalent tov[key] = elem. Alternative suggest names welcome.