On Tue, Jun 30, 2020 at 6:39 PM 'Dan Kortschak' via golang-nuts
<
golan...@googlegroups.com> wrote:
>
> Is there a reason not to retain the returned value from `mapiterkey` on
> line 1243 of reflect/value.go[1] for use on line 1249[2].
>
> ```
> // Key returns the key of the iterator's current map entry.
> func (it *MapIter) Key() Value {
> if
it.it == nil {
> panic("MapIter.Key called before Next")
> }
> if mapiterkey(
it.it) == nil { //L1243
> panic("MapIter.Key called on exhausted iterator")
> }
>
> t := (*mapType)(unsafe.Pointer(it.m.typ))
> ktype := t.key
> return copyVal(ktype,
it.m.flag.ro()|flag(ktype.Kind()), mapiterkey(
it.it)) // L1249
> }
> ```
>
> The same question applies to `*MapIter.Value` method just below `Key`.
I don't think there is any reason to call the function twice. The