]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: don't clear pointer-free memory when growing maps
authorJosh Bleecher Snyder <josharian@gmail.com>
Sat, 19 Aug 2017 17:45:38 +0000 (10:45 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Sun, 20 Aug 2017 15:46:43 +0000 (15:46 +0000)
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>
src/runtime/hashmap.go

index 17a69646ca07156e51e97239c8543668a175e1a5..efb8a780243b48d245af9d65d52174890ce9c969 100644 (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)
                }
        }