Commit 619af172 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

runtime: refactor hmap setoverflow into newoverflow

This simplifies the code, as well as providing
a single place to modify to change the
allocation of new overflow buckets.

Updates #19931
Updates #19992

Change-Id: I77070619f5c8fe449bbc35278278bca5eda780f2
Reviewed-on: https://go-review.googlesource.com/40975
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent dc444418
...@@ -196,13 +196,15 @@ func (h *hmap) incrnoverflow() { ...@@ -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() h.incrnoverflow()
if t.bucket.kind&kindNoPointers != 0 { if t.bucket.kind&kindNoPointers != 0 {
h.createOverflow() h.createOverflow()
*h.overflow[0] = append(*h.overflow[0], ovf) *h.overflow[0] = append(*h.overflow[0], ovf)
} }
*(**bmap)(add(unsafe.Pointer(b), uintptr(t.bucketsize)-sys.PtrSize)) = ovf *(**bmap)(add(unsafe.Pointer(b), uintptr(t.bucketsize)-sys.PtrSize)) = ovf
return ovf
} }
func (h *hmap) createOverflow() { func (h *hmap) createOverflow() {
...@@ -565,8 +567,7 @@ again: ...@@ -565,8 +567,7 @@ again:
if inserti == nil { if inserti == nil {
// all current buckets are full, allocate a new one. // all current buckets are full, allocate a new one.
newb := (*bmap)(newobject(t.bucket)) newb := h.newoverflow(t, b)
h.setoverflow(t, b, newb)
inserti = &newb.tophash[0] inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset) insertk = add(unsafe.Pointer(newb), dataOffset)
val = add(insertk, bucketCnt*uintptr(t.keysize)) val = add(insertk, bucketCnt*uintptr(t.keysize))
...@@ -1045,8 +1046,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { ...@@ -1045,8 +1046,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
if useX { if useX {
b.tophash[i] = evacuatedX b.tophash[i] = evacuatedX
if xi == bucketCnt { if xi == bucketCnt {
newx := (*bmap)(newobject(t.bucket)) newx := h.newoverflow(t, x)
h.setoverflow(t, x, newx)
x = newx x = newx
xi = 0 xi = 0
xk = add(unsafe.Pointer(x), dataOffset) xk = add(unsafe.Pointer(x), dataOffset)
...@@ -1069,8 +1069,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) { ...@@ -1069,8 +1069,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
} else { } else {
b.tophash[i] = evacuatedY b.tophash[i] = evacuatedY
if yi == bucketCnt { if yi == bucketCnt {
newy := (*bmap)(newobject(t.bucket)) newy := h.newoverflow(t, y)
h.setoverflow(t, y, newy)
y = newy y = newy
yi = 0 yi = 0
yk = add(unsafe.Pointer(y), dataOffset) yk = add(unsafe.Pointer(y), dataOffset)
......
...@@ -490,8 +490,7 @@ again: ...@@ -490,8 +490,7 @@ again:
if inserti == nil { if inserti == nil {
// all current buckets are full, allocate a new one. // all current buckets are full, allocate a new one.
newb := (*bmap)(newobject(t.bucket)) newb := h.newoverflow(t, b)
h.setoverflow(t, b, newb)
inserti = &newb.tophash[0] inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset) insertk = add(unsafe.Pointer(newb), dataOffset)
val = add(insertk, bucketCnt*4) val = add(insertk, bucketCnt*4)
...@@ -579,8 +578,7 @@ again: ...@@ -579,8 +578,7 @@ again:
if inserti == nil { if inserti == nil {
// all current buckets are full, allocate a new one. // all current buckets are full, allocate a new one.
newb := (*bmap)(newobject(t.bucket)) newb := h.newoverflow(t, b)
h.setoverflow(t, b, newb)
inserti = &newb.tophash[0] inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset) insertk = add(unsafe.Pointer(newb), dataOffset)
val = add(insertk, bucketCnt*8) val = add(insertk, bucketCnt*8)
...@@ -673,8 +671,7 @@ again: ...@@ -673,8 +671,7 @@ again:
if inserti == nil { if inserti == nil {
// all current buckets are full, allocate a new one. // all current buckets are full, allocate a new one.
newb := (*bmap)(newobject(t.bucket)) newb := h.newoverflow(t, b)
h.setoverflow(t, b, newb)
inserti = &newb.tophash[0] inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset) insertk = add(unsafe.Pointer(newb), dataOffset)
val = add(insertk, bucketCnt*2*sys.PtrSize) val = add(insertk, bucketCnt*2*sys.PtrSize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment