diff options
| author | Martin Möhrmann <moehrmann@google.com> | 2017-08-31 21:26:03 +0200 |
|---|---|---|
| committer | Martin Möhrmann <moehrmann@google.com> | 2017-09-06 04:00:51 +0000 |
| commit | 034d825ea304a87e4df4f3edad7d3cfcbfc9c526 (patch) | |
| tree | 2f24099fa8af4d35e4f2861c303bbec4434eea8d /src/runtime/hashmap.go | |
| parent | 9c3f2685589e05c21563c583b683d00703eb0090 (diff) | |
| download | go-034d825ea304a87e4df4f3edad7d3cfcbfc9c526.tar.xz | |
runtime: avoid redundant zeroing of hiter
The compiler and reflect already zero hiter before mapiterinit.
While here expand the documentation for mapiterinit.
Change-Id: I78b05d4d14bf78e8091e5353cdac80ffed30ca1e
Reviewed-on: https://go-review.googlesource.com/60673
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/hashmap.go')
| -rw-r--r-- | src/runtime/hashmap.go | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index bf5d51ab8f..1e76fc590c 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -678,25 +678,17 @@ search: h.flags &^= hashWriting } +// mapiterinit initializes the hiter struct used for ranging over maps. +// The hiter struct pointed to by 'it' is allocated on the stack +// by the compilers order pass or on the heap by reflect_mapiterinit. +// Both need to have zeroed hiter since the struct contains pointers. func mapiterinit(t *maptype, h *hmap, it *hiter) { - // Clear pointer fields so garbage collector does not complain. - it.key = nil - it.value = nil - it.t = nil - it.h = nil - it.buckets = nil - it.bptr = nil - it.overflow[0] = nil - it.overflow[1] = nil - if raceenabled && h != nil { callerpc := getcallerpc(unsafe.Pointer(&t)) racereadpc(unsafe.Pointer(h), callerpc, funcPC(mapiterinit)) } if h == nil || h.count == 0 { - it.key = nil - it.value = nil return } @@ -728,11 +720,9 @@ func mapiterinit(t *maptype, h *hmap, it *hiter) { // iterator state it.bucket = it.startBucket - it.wrapped = false - it.bptr = nil // Remember we have an iterator. - // Can run concurrently with another hash_iter_init(). + // Can run concurrently with another mapiterinit(). if old := h.flags; old&(iterator|oldIterator) != iterator|oldIterator { atomic.Or8(&h.flags, iterator|oldIterator) } |
