diff --git a/src/runtime/hashmap.go b/src/runtime/hashmap.go index 9b214a3ac2..4b958605fd 100644 --- a/src/runtime/hashmap.go +++ b/src/runtime/hashmap.go @@ -196,13 +196,15 @@ func (h *hmap) incrnoverflow() { } } -func (h *hmap) setoverflow(t *maptype, b, ovf *bmap) { +func (h *hmap) newoverflow(t *maptype, b *bmap) *bmap { + ovf := (*bmap)(newobject(t.bucket)) h.incrnoverflow() if t.bucket.kind&kindNoPointers != 0 { h.createOverflow() *h.overflow[0] = append(*h.overflow[0], ovf) } *(**bmap)(add(unsafe.Pointer(b), uintptr(t.bucketsize)-sys.PtrSize)) = ovf + return ovf } func (h *hmap) createOverflow() { @@ -565,8 +567,7 @@ again: if inserti == nil { // all current buckets are full, allocate a new one. - newb := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, b, newb) + newb := h.newoverflow(t, b) inserti = &newb.tophash[0] insertk = add(unsafe.Pointer(newb), dataOffset) val = add(insertk, bucketCnt*uintptr(t.keysize)) @@ -1045,8 +1046,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { if useX { b.tophash[i] = evacuatedX if xi == bucketCnt { - newx := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, x, newx) + newx := h.newoverflow(t, x) x = newx xi = 0 xk = add(unsafe.Pointer(x), dataOffset) @@ -1069,8 +1069,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { } else { b.tophash[i] = evacuatedY if yi == bucketCnt { - newy := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, y, newy) + newy := h.newoverflow(t, y) y = newy yi = 0 yk = add(unsafe.Pointer(y), dataOffset) diff --git a/src/runtime/hashmap_fast.go b/src/runtime/hashmap_fast.go index 0a625cca56..ebba001d46 100644 --- a/src/runtime/hashmap_fast.go +++ b/src/runtime/hashmap_fast.go @@ -490,8 +490,7 @@ again: if inserti == nil { // all current buckets are full, allocate a new one. - newb := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, b, newb) + newb := h.newoverflow(t, b) inserti = &newb.tophash[0] insertk = add(unsafe.Pointer(newb), dataOffset) val = add(insertk, bucketCnt*4) @@ -579,8 +578,7 @@ again: if inserti == nil { // all current buckets are full, allocate a new one. - newb := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, b, newb) + newb := h.newoverflow(t, b) inserti = &newb.tophash[0] insertk = add(unsafe.Pointer(newb), dataOffset) val = add(insertk, bucketCnt*8) @@ -673,8 +671,7 @@ again: if inserti == nil { // all current buckets are full, allocate a new one. - newb := (*bmap)(newobject(t.bucket)) - h.setoverflow(t, b, newb) + newb := h.newoverflow(t, b) inserti = &newb.tophash[0] insertk = add(unsafe.Pointer(newb), dataOffset) val = add(insertk, bucketCnt*2*sys.PtrSize)