1
0
mirror of https://github.com/golang/go synced 2024-11-19 13:54:56 -07:00

runtime: don't clear pointer-free memory when growing maps

If there are no pointers, then clearing memory doesn't help GC,
and the memory is otherwise dead, so don't bother clearing it.

Change-Id: I953f4a3264939f2825e82292030eda2e835cbb97
Reviewed-on: https://go-review.googlesource.com/57350
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
This commit is contained in:
Josh Bleecher Snyder 2017-08-19 10:45:38 -07:00
parent ff90f4af66
commit 3f972df4a7

View File

@ -1124,17 +1124,13 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
}
}
// Unlink the overflow buckets & clear key/value to help GC.
if h.flags&oldIterator == 0 {
b = (*bmap)(add(h.oldbuckets, oldbucket*uintptr(t.bucketsize)))
if h.flags&oldIterator == 0 && t.bucket.kind&kindNoPointers == 0 {
b := add(h.oldbuckets, oldbucket*uintptr(t.bucketsize))
// Preserve b.tophash because the evacuation
// state is maintained there.
ptr := add(unsafe.Pointer(b), dataOffset)
ptr := add(b, dataOffset)
n := uintptr(t.bucketsize) - dataOffset
if t.bucket.kind&kindNoPointers == 0 {
memclrHasPointers(ptr, n)
} else {
memclrNoHeapPointers(ptr, n)
}
memclrHasPointers(ptr, n)
}
}