Skip to content

Commit a3aa46a

Browse files
reflect: use MapMaxKeyBytes,MapMaxElemBytes,MapBucketCount of internal/abi
For #59670
1 parent 9b4b3e5 commit a3aa46a

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

src/reflect/type.go

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,13 +1694,13 @@ func MapOf(key, elem Type) Type {
16941694
return typehash(ktyp, p, seed)
16951695
}
16961696
mt.Flags = 0
1697-
if ktyp.Size_ > maxKeySize {
1697+
if ktyp.Size_ > abi.MapMaxKeyBytes {
16981698
mt.KeySize = uint8(goarch.PtrSize)
16991699
mt.Flags |= 1 // indirect key
17001700
} else {
17011701
mt.KeySize = uint8(ktyp.Size_)
17021702
}
1703-
if etyp.Size_ > maxValSize {
1703+
if etyp.Size_ > abi.MapMaxElemBytes {
17041704
mt.ValueSize = uint8(goarch.PtrSize)
17051705
mt.Flags |= 2 // indirect value
17061706
} else {
@@ -1954,21 +1954,11 @@ func hashMightPanic(t *abi.Type) bool {
19541954
}
19551955
}
19561956

1957-
// Make sure these routines stay in sync with ../runtime/map.go!
1958-
// These types exist only for GC, so we only fill out GC relevant info.
1959-
// Currently, that's just size and the GC program. We also fill in string
1960-
// for possible debugging use.
1961-
const (
1962-
bucketSize uintptr = abi.MapBucketCount
1963-
maxKeySize uintptr = abi.MapMaxKeyBytes
1964-
maxValSize uintptr = abi.MapMaxElemBytes
1965-
)
1966-
19671957
func bucketOf(ktyp, etyp *abi.Type) *abi.Type {
1968-
if ktyp.Size_ > maxKeySize {
1958+
if ktyp.Size_ > abi.MapMaxKeyBytes {
19691959
ktyp = ptrTo(ktyp)
19701960
}
1971-
if etyp.Size_ > maxValSize {
1961+
if etyp.Size_ > abi.MapMaxElemBytes {
19721962
etyp = ptrTo(etyp)
19731963
}
19741964

@@ -1980,29 +1970,29 @@ func bucketOf(ktyp, etyp *abi.Type) *abi.Type {
19801970
var gcdata *byte
19811971
var ptrdata uintptr
19821972

1983-
size := bucketSize*(1+ktyp.Size_+etyp.Size_) + goarch.PtrSize
1973+
size := abi.MapBucketCount*(1+ktyp.Size_+etyp.Size_) + goarch.PtrSize
19841974
if size&uintptr(ktyp.Align_-1) != 0 || size&uintptr(etyp.Align_-1) != 0 {
19851975
panic("reflect: bad size computation in MapOf")
19861976
}
19871977

19881978
if ktyp.PtrBytes != 0 || etyp.PtrBytes != 0 {
1989-
nptr := (bucketSize*(1+ktyp.Size_+etyp.Size_) + goarch.PtrSize) / goarch.PtrSize
1979+
nptr := (abi.MapBucketCount*(1+ktyp.Size_+etyp.Size_) + goarch.PtrSize) / goarch.PtrSize
19901980
n := (nptr + 7) / 8
19911981

19921982
// Runtime needs pointer masks to be a multiple of uintptr in size.
19931983
n = (n + goarch.PtrSize - 1) &^ (goarch.PtrSize - 1)
19941984
mask := make([]byte, n)
1995-
base := bucketSize / goarch.PtrSize
1985+
base := uintptr(abi.MapBucketCount / goarch.PtrSize)
19961986

19971987
if ktyp.PtrBytes != 0 {
1998-
emitGCMask(mask, base, ktyp, bucketSize)
1988+
emitGCMask(mask, base, ktyp, abi.MapBucketCount)
19991989
}
2000-
base += bucketSize * ktyp.Size_ / goarch.PtrSize
1990+
base += abi.MapBucketCount * ktyp.Size_ / goarch.PtrSize
20011991

20021992
if etyp.PtrBytes != 0 {
2003-
emitGCMask(mask, base, etyp, bucketSize)
1993+
emitGCMask(mask, base, etyp, abi.MapBucketCount)
20041994
}
2005-
base += bucketSize * etyp.Size_ / goarch.PtrSize
1995+
base += abi.MapBucketCount * etyp.Size_ / goarch.PtrSize
20061996

20071997
word := base
20081998
mask[word/8] |= 1 << (word % 8)

src/reflect/value.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ func (v Value) MapIndex(key Value) Value {
18141814
// of unexported fields.
18151815

18161816
var e unsafe.Pointer
1817-
if (tt.Key == stringType || key.kind() == String) && tt.Key == key.typ() && tt.Elem.Size() <= maxValSize {
1817+
if (tt.Key == stringType || key.kind() == String) && tt.Key == key.typ() && tt.Elem.Size() <= abi.MapMaxElemBytes {
18181818
k := *(*string)(key.ptr)
18191819
e = mapaccess_faststr(v.typ(), v.pointer(), k)
18201820
} else {
@@ -2450,7 +2450,7 @@ func (v Value) SetMapIndex(key, elem Value) {
24502450
key.mustBeExported()
24512451
tt := (*mapType)(unsafe.Pointer(v.typ()))
24522452

2453-
if (tt.Key == stringType || key.kind() == String) && tt.Key == key.typ() && tt.Elem.Size() <= maxValSize {
2453+
if (tt.Key == stringType || key.kind() == String) && tt.Key == key.typ() && tt.Elem.Size() <= abi.MapMaxElemBytes {
24542454
k := *(*string)(key.ptr)
24552455
if elem.typ() == nil {
24562456
mapdelete_faststr(v.typ(), v.pointer(), k)

0 commit comments

Comments
 (0)