On Tue, Jun 30, 2020 at 6:39 PM 'Dan Kortschak' via golang-nuts
<golang-nuts@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
value could be retained.

I think the functionswill be inlined, so it probably won't make any
performance difference, but it might be a little clearer.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUWyV5SHi9pw2n-jFJ%3D-e2dLcUqfNz2pJgL%2BkvwyR4tCA%40mail.gmail.com.

Reply via email to