mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: refer to map elements as elements instead of values
The spec carefully and consistently uses "key" and "element" as map terminology. The implementation, not so much. This change attempts to make the implementation consistently hew to the spec's terminology. Beyond consistency, this has the advantage of avoid some confusion and naming collisions, since v and value are very generic and commonly used terms. I believe that I found all everything, but there are a lot of non-obvious places for these to hide, and grepping for them is hard. Hopefully this change changes enough of them that we will start using elem going forward. Any remaining hidden cases can be removed ad hoc as they are discovered. The only externally-facing part of this change is in package reflect, where there is a minor doc change and a function parameter name change. Updates #27167 Change-Id: I2f2d78f16c360dc39007b9966d5c2046a29d3701 Reviewed-on: https://go-review.googlesource.com/c/go/+/174523 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
a8d0047e47
commit
73cb9a1cb3
10 changed files with 222 additions and 223 deletions
|
|
@ -15,7 +15,7 @@ func typecheckrange(n *Node) {
|
|||
// Typechecking order is important here:
|
||||
// 0. first typecheck range expression (slice/map/chan),
|
||||
// it is evaluated only once and so logically it is not part of the loop.
|
||||
// 1. typcheck produced values,
|
||||
// 1. typecheck produced values,
|
||||
// this part can declare new vars and so it must be typechecked before body,
|
||||
// because body can contain a closure that captures the vars.
|
||||
// 2. decldepth++ to denote loop body.
|
||||
|
|
@ -298,8 +298,8 @@ func walkrange(n *Node) *Node {
|
|||
hit := prealloc[n]
|
||||
th := hit.Type
|
||||
n.Left = nil
|
||||
keysym := th.Field(0).Sym // depends on layout of iterator struct. See reflect.go:hiter
|
||||
valsym := th.Field(1).Sym // ditto
|
||||
keysym := th.Field(0).Sym // depends on layout of iterator struct. See reflect.go:hiter
|
||||
elemsym := th.Field(1).Sym // ditto
|
||||
|
||||
fn := syslook("mapiterinit")
|
||||
|
||||
|
|
@ -318,11 +318,11 @@ func walkrange(n *Node) *Node {
|
|||
} else if v2 == nil {
|
||||
body = []*Node{nod(OAS, v1, key)}
|
||||
} else {
|
||||
val := nodSym(ODOT, hit, valsym)
|
||||
val = nod(ODEREF, val, nil)
|
||||
elem := nodSym(ODOT, hit, elemsym)
|
||||
elem = nod(ODEREF, elem, nil)
|
||||
a := nod(OAS2, nil, nil)
|
||||
a.List.Set2(v1, v2)
|
||||
a.Rlist.Set2(key, val)
|
||||
a.Rlist.Set2(key, elem)
|
||||
body = []*Node{a}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue