]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: refactor out tophash calculation
authorJosh Bleecher Snyder <josharian@gmail.com>
Wed, 7 Jun 2017 16:55:05 +0000 (09:55 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 15 Aug 2017 00:20:06 +0000 (00:20 +0000)
No functional changes; tophash is inlined.

Change-Id: Ic8ce95b3622eafbddcfbc97f8c630ab8c5bfe7ad
Reviewed-on: https://go-review.googlesource.com/55233
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/hashmap.go
src/runtime/hashmap_fast.go

index d45bfdfe343d8023c8905a76e2f4f388b5bd6e01..3e413e52f7dc27583a4517231109c9bd0191b182 100644 (file)
@@ -170,6 +170,15 @@ type hiter struct {
        checkBucket uintptr
 }
 
+// tophash calculates the tophash value for hash.
+func tophash(hash uintptr) uint8 {
+       top := uint8(hash >> (sys.PtrSize*8 - 8))
+       if top < minTopHash {
+               top += minTopHash
+       }
+       return top
+}
+
 func evacuated(b *bmap) bool {
        h := b.tophash[0]
        return h > empty && h < minTopHash
@@ -374,10 +383,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
                        b = oldb
                }
        }
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -432,10 +438,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
                        b = oldb
                }
        }
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -479,10 +482,7 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe
                        b = oldb
                }
        }
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -557,10 +557,7 @@ again:
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
 
        var inserti *uint8
        var insertk unsafe.Pointer
@@ -667,10 +664,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) {
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -1102,10 +1096,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
                                                } else {
                                                        hash &^= newbit
                                                }
-                                               top = uint8(hash >> (sys.PtrSize*8 - 8))
-                                               if top < minTopHash {
-                                                       top += minTopHash
-                                               }
+                                               top = tophash(hash)
                                        }
                                        if hash&newbit != 0 {
                                                useY = 1
index e7a719d63f73494bcaa0400acc7c3117e8ef9cd9..c3ce5ae150e469b0fa2cf5528d4985fb4109b7a0 100644 (file)
@@ -281,10 +281,7 @@ dohash:
                        b = oldb
                }
        }
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -385,10 +382,7 @@ dohash:
                        b = oldb
                }
        }
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -435,10 +429,7 @@ again:
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
 
        var inserti *uint8
        var insertk unsafe.Pointer
@@ -523,10 +514,7 @@ again:
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
 
        var inserti *uint8
        var insertk unsafe.Pointer
@@ -612,10 +600,7 @@ again:
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
 
        var inserti *uint8
        var insertk unsafe.Pointer
@@ -700,10 +685,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) {
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -755,10 +737,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) {
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {
@@ -811,10 +790,7 @@ func mapdelete_faststr(t *maptype, h *hmap, ky string) {
                growWork(t, h, bucket)
        }
        b := (*bmap)(unsafe.Pointer(uintptr(h.buckets) + bucket*uintptr(t.bucketsize)))
-       top := uint8(hash >> (sys.PtrSize*8 - 8))
-       if top < minTopHash {
-               top += minTopHash
-       }
+       top := tophash(hash)
        for {
                for i := uintptr(0); i < bucketCnt; i++ {
                        if b.tophash[i] != top {