Skip to content

Commit fdb2008

Browse files
qiulaidongfengrandall77
authored andcommitted
runtime: use MapMaxKeyBytes,MapMaxElemBytes,MapBucketCount of internal/abi
For #59670 Change-Id: I9265e033bf3a84c3dc7b4a5d52c0df9672435f0d GitHub-Last-Rev: 8e40990 GitHub-Pull-Request: #64774 Reviewed-on: https://go-review.googlesource.com/c/go/+/550117 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Than McIntosh <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 24070cf commit fdb2008

File tree

7 files changed

+137
-140
lines changed

7 files changed

+137
-140
lines changed

src/cmd/compile/internal/walk/walk.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package walk
66

77
import (
88
"fmt"
9+
"internal/abi"
910

1011
"cmd/compile/internal/base"
1112
"cmd/compile/internal/ir"
@@ -183,8 +184,7 @@ var mapassign = mkmapnames("mapassign", "ptr")
183184
var mapdelete = mkmapnames("mapdelete", "")
184185

185186
func mapfast(t *types.Type) int {
186-
// Check runtime/map.go:maxElemSize before changing.
187-
if t.Elem().Size() > 128 {
187+
if t.Elem().Size() > abi.MapMaxElemBytes {
188188
return mapslow
189189
}
190190
switch reflectdata.AlgType(t.Key()) {

src/internal/abi/map.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ package abi
77
// Map constants common to several packages
88
// runtime/runtime-gdb.py:MapTypePrinter contains its own copy
99
const (
10+
// Maximum number of key/elem pairs a bucket can hold.
1011
MapBucketCountBits = 3 // log2 of number of elements in a bucket.
1112
MapBucketCount = 1 << MapBucketCountBits
12-
MapMaxKeyBytes = 128 // Must fit in a uint8.
13-
MapMaxElemBytes = 128 // Must fit in a uint8.
13+
14+
// Maximum key or elem size to keep inline (instead of mallocing per element).
15+
// Must fit in a uint8.
16+
// Note: fast map functions cannot handle big elems (bigger than MapMaxElemBytes).
17+
MapMaxKeyBytes = 128
18+
MapMaxElemBytes = 128 // Must fit in a uint8.
1419
)
1520

1621
// ZeroValSize is the size in bytes of runtime.zeroVal.

src/runtime/export_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,15 +751,15 @@ func MapTombstoneCheck(m map[int]int) {
751751
b0 := (*bmap)(add(h.buckets, uintptr(x)*uintptr(t.BucketSize)))
752752
n := 0
753753
for b := b0; b != nil; b = b.overflow(t) {
754-
for i := 0; i < bucketCnt; i++ {
754+
for i := 0; i < abi.MapBucketCount; i++ {
755755
if b.tophash[i] != emptyRest {
756756
n++
757757
}
758758
}
759759
}
760760
k := 0
761761
for b := b0; b != nil; b = b.overflow(t) {
762-
for i := 0; i < bucketCnt; i++ {
762+
for i := 0; i < abi.MapBucketCount; i++ {
763763
if k < n && b.tophash[i] == emptyRest {
764764
panic("early emptyRest")
765765
}

0 commit comments

Comments
 (0)