Skip to content

proposal: reflect: add Value.SetMapIndexOf #57061

@dsnet

Description

@dsnet

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions