Skip to content

runtime: use MapMaxKeyBytes,MapMaxElemBytes,MapBucketCount of internal/abi #64774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmd/compile/internal/walk/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package walk

import (
"fmt"
"internal/abi"

"cmd/compile/internal/base"
"cmd/compile/internal/ir"
Expand Down Expand Up @@ -188,8 +189,7 @@ var mapassign = mkmapnames("mapassign", "ptr")
var mapdelete = mkmapnames("mapdelete", "")

func mapfast(t *types.Type) int {
// Check runtime/map.go:maxElemSize before changing.
if t.Elem().Size() > 128 {
if t.Elem().Size() > abi.MapMaxElemBytes {
return mapslow
}
switch reflectdata.AlgType(t.Key()) {
Expand Down
9 changes: 7 additions & 2 deletions src/internal/abi/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ package abi
// Map constants common to several packages
// runtime/runtime-gdb.py:MapTypePrinter contains its own copy
const (
// Maximum number of key/elem pairs a bucket can hold.
MapBucketCountBits = 3 // log2 of number of elements in a bucket.
MapBucketCount = 1 << MapBucketCountBits
MapMaxKeyBytes = 128 // Must fit in a uint8.
MapMaxElemBytes = 128 // Must fit in a uint8.

// Maximum key or elem size to keep inline (instead of mallocing per element).
// Must fit in a uint8.
// Note: fast map functions cannot handle big elems (bigger than MapMaxElemBytes).
MapMaxKeyBytes = 128
MapMaxElemBytes = 128 // Must fit in a uint8.
)

// ZeroValSize is the size in bytes of runtime.zeroVal.
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,15 +751,15 @@ func MapTombstoneCheck(m map[int]int) {
b0 := (*bmap)(add(h.buckets, uintptr(x)*uintptr(t.BucketSize)))
n := 0
for b := b0; b != nil; b = b.overflow(t) {
for i := 0; i < bucketCnt; i++ {
for i := 0; i < abi.MapBucketCount; i++ {
if b.tophash[i] != emptyRest {
n++
}
}
}
k := 0
for b := b0; b != nil; b = b.overflow(t) {
for i := 0; i < bucketCnt; i++ {
for i := 0; i < abi.MapBucketCount; i++ {
if k < n && b.tophash[i] == emptyRest {
panic("early emptyRest")
}
Expand Down
Loading