mirror of
https://github.com/golang/go.git
synced 2026-02-01 08:32:04 +03:00
internal/runtime: cleaner overflow checker
remove todo
Change-Id: I4b10d7a8c26bea9296b321f53abd0330f2afc35a
GitHub-Last-Rev: b939acc287
GitHub-Pull-Request: golang/go#74943
Reviewed-on: https://go-review.googlesource.com/c/go/+/694236
Auto-Submit: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
@@ -8,6 +8,7 @@ package maps
|
||||
import (
|
||||
"internal/abi"
|
||||
"internal/goarch"
|
||||
"internal/runtime/math"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@@ -127,8 +128,7 @@ func (t *table) maxGrowthLeft() uint16 {
|
||||
// single-group tables, we could fill all slots.
|
||||
return t.capacity - 1
|
||||
} else {
|
||||
if t.capacity*maxAvgGroupLoad < t.capacity {
|
||||
// TODO(prattmic): Do something cleaner.
|
||||
if t.capacity > math.MaxUint16/maxAvgGroupLoad {
|
||||
panic("overflow")
|
||||
}
|
||||
return (t.capacity * maxAvgGroupLoad) / abi.MapGroupSlots
|
||||
|
||||
@@ -7,6 +7,7 @@ package math
|
||||
import "internal/goarch"
|
||||
|
||||
const (
|
||||
MaxUint16 = ^uint16(0)
|
||||
MaxUint32 = ^uint32(0)
|
||||
MaxUint64 = ^uint64(0)
|
||||
MaxUintptr = ^uintptr(0)
|
||||
|
||||
Reference in New Issue
Block a user