mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: move hiter, hmap, and scase definitions into builtin.go
Also eliminates per-maptype hiter and hmap types, since they're not really needed anyway. Update packages reflect and runtime accordingly. Reduces golang.org/x/tools/cmd/godoc's text segment by ~170kB: text data bss dec hex filename 13085702 140640 151520 13377862 cc2146 godoc.before 12915382 140640 151520 13207542 c987f6 godoc.after Updates #6853. Change-Id: I948b2bc1f22d477c1756204996b4e3e1fb568d81 Reviewed-on: https://go-review.googlesource.com/16610 Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
d0c11577b9
commit
f28bbb776a
14 changed files with 94 additions and 163 deletions
|
|
@ -102,6 +102,7 @@ const (
|
|||
)
|
||||
|
||||
// A header for a Go map.
|
||||
// Changes here must also be made in src/cmd/compile/internal/gc/builtin/runtime.go.
|
||||
type hmap struct {
|
||||
// Note: the format of the Hmap is encoded in ../../cmd/internal/gc/reflect.go and
|
||||
// ../reflect/type.go. Don't change this structure without also changing that code!
|
||||
|
|
@ -137,11 +138,10 @@ type bmap struct {
|
|||
}
|
||||
|
||||
// A hash iteration structure.
|
||||
// If you modify hiter, also change cmd/internal/gc/reflect.go to indicate
|
||||
// the layout of this structure.
|
||||
// Changes here must also be made in src/cmd/compile/internal/gc/builtin/runtime.go.
|
||||
type hiter struct {
|
||||
key unsafe.Pointer // Must be in first position. Write nil to indicate iteration end (see cmd/internal/gc/range.go).
|
||||
value unsafe.Pointer // Must be in second position (see cmd/internal/gc/range.go).
|
||||
key unsafe.Pointer // Write nil to indicate iteration end (see cmd/compile/internal/gc/range.go).
|
||||
value unsafe.Pointer
|
||||
t *maptype
|
||||
h *hmap
|
||||
buckets unsafe.Pointer // bucket ptr at hash_iter initialization time
|
||||
|
|
@ -188,11 +188,10 @@ func (h *hmap) createOverflow() {
|
|||
// If h != nil, the map can be created directly in h.
|
||||
// If bucket != nil, bucket can be used as the first bucket.
|
||||
func makemap(t *maptype, hint int64, h *hmap, bucket unsafe.Pointer) *hmap {
|
||||
if sz := unsafe.Sizeof(hmap{}); sz > 48 || sz != uintptr(t.hmap.size) {
|
||||
println("runtime: sizeof(hmap) =", sz, ", t.hmap.size =", t.hmap.size)
|
||||
if sz := unsafe.Sizeof(hmap{}); sz > 48 {
|
||||
println("runtime: sizeof(hmap) =", sz)
|
||||
throw("bad hmap size")
|
||||
}
|
||||
|
||||
if hint < 0 || int64(int32(hint)) != hint {
|
||||
panic("makemap: size out of range")
|
||||
// TODO: make hint an int, then none of this nonsense
|
||||
|
|
@ -254,7 +253,7 @@ func makemap(t *maptype, hint int64, h *hmap, bucket unsafe.Pointer) *hmap {
|
|||
|
||||
// initialize Hmap
|
||||
if h == nil {
|
||||
h = (*hmap)(newobject(t.hmap))
|
||||
h = &hmap{}
|
||||
}
|
||||
h.count = 0
|
||||
h.B = B
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue