]> Cypherpunks repositories - gostls13.git/commitdiff
internal/abi, runtime, reflect, cmd: merge maxZero const into internal/abi
authorqiulaidongfeng <2645477756@qq.com>
Tue, 21 Nov 2023 22:57:59 +0000 (22:57 +0000)
committerKeith Randall <khr@golang.org>
Wed, 22 Nov 2023 03:56:03 +0000 (03:56 +0000)
For #59670

Change-Id: If38a74ad067a3ea3ff551c0c25c8ef41abec114b
GitHub-Last-Rev: fb1f2f3c9f320017627bc3342b061e1e7f6f7fad
GitHub-Pull-Request: golang/go#64268
Reviewed-on: https://go-review.googlesource.com/c/go/+/543655
Run-TryBot: qiulaidongfeng <2645477756@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/walk/assign.go
src/cmd/compile/internal/walk/expr.go
src/cmd/compile/internal/walk/walk.go
src/internal/abi/map.go
src/reflect/value.go
src/runtime/map.go

index afd1a326d348558968cb39ac1a573746b24fec52..fc3b858a8096fdca14ec47a32558f3a63b3708d3 100644 (file)
@@ -6,6 +6,7 @@ package walk
 
 import (
        "go/constant"
+       "internal/abi"
 
        "cmd/compile/internal/base"
        "cmd/compile/internal/ir"
@@ -168,7 +169,7 @@ func walkAssignMapRead(init *ir.Nodes, n *ir.AssignListStmt) ir.Node {
        a := n.Lhs[0]
 
        var call *ir.CallExpr
-       if w := t.Elem().Size(); w <= zeroValSize {
+       if w := t.Elem().Size(); w <= abi.ZeroValSize {
                fn := mapfn(mapaccess2[fast], t, false)
                call = mkcall1(fn, fn.Type().ResultsTuple(), init, reflectdata.IndexMapRType(base.Pos, r), r.X, key)
        } else {
index 64d20b555e41e849ae99cdb7598d08541c672d81..268f793dc966fb614f2b02d7928af4f23a71c8e4 100644 (file)
@@ -7,6 +7,7 @@ package walk
 import (
        "fmt"
        "go/constant"
+       "internal/abi"
        "internal/buildcfg"
        "strings"
 
@@ -825,7 +826,7 @@ func walkIndexMap(n *ir.IndexExpr, init *ir.Nodes) ir.Node {
        switch {
        case n.Assigned:
                mapFn = mapfn(mapassign[fast], t, false)
-       case t.Elem().Size() > zeroValSize:
+       case t.Elem().Size() > abi.ZeroValSize:
                args = append(args, reflectdata.ZeroAddr(t.Elem().Size()))
                mapFn = mapfn("mapaccess1_fat", t, true)
        default:
index 8be5804616bea628b9b76cdd6eb5a8bd0a23f4e2..001edcc3325c223c6cb72785c03b913a1c0e0f4e 100644 (file)
@@ -18,7 +18,6 @@ import (
 
 // The constant is known to runtime.
 const tmpstringbufsize = 32
-const zeroValSize = 1024 // must match value of runtime/map.go:maxZero
 
 func Walk(fn *ir.Func) {
        ir.CurFunc = fn
index e5b0a0bb6f366c13c6ad24158082fe41451494ac..ad054e7d77799619be59066c069dc9701f06f7f4 100644 (file)
@@ -12,3 +12,6 @@ const (
        MapMaxKeyBytes     = 128 // Must fit in a uint8.
        MapMaxElemBytes    = 128 // Must fit in a uint8.
 )
+
+// ZeroValSize is the size in bytes of runtime.zeroVal.
+const ZeroValSize = 1024
index 068bac005073db07e3001501cdc87e5cd0ddd8a5..06f22f7428139f57d06412662cf9cd3880626111 100644 (file)
@@ -1603,7 +1603,7 @@ func (v Value) IsZero() bool {
                }
                typ := (*abi.ArrayType)(unsafe.Pointer(v.typ()))
                // If the type is comparable, then compare directly with zero.
-               if typ.Equal != nil && typ.Size() <= maxZero {
+               if typ.Equal != nil && typ.Size() <= abi.ZeroValSize {
                        // v.ptr doesn't escape, as Equal functions are compiler generated
                        // and never escape. The escape analysis doesn't know, as it is a
                        // function pointer call.
@@ -1631,7 +1631,7 @@ func (v Value) IsZero() bool {
                }
                typ := (*abi.StructType)(unsafe.Pointer(v.typ()))
                // If the type is comparable, then compare directly with zero.
-               if typ.Equal != nil && typ.Size() <= maxZero {
+               if typ.Equal != nil && typ.Size() <= abi.ZeroValSize {
                        // See noescape justification above.
                        return typ.Equal(noescape(v.ptr), unsafe.Pointer(&zeroVal[0]))
                }
@@ -3277,7 +3277,7 @@ func Zero(typ Type) Value {
        fl := flag(t.Kind())
        if t.IfaceIndir() {
                var p unsafe.Pointer
-               if t.Size() <= maxZero {
+               if t.Size() <= abi.ZeroValSize {
                        p = unsafe.Pointer(&zeroVal[0])
                } else {
                        p = unsafe_New(t)
@@ -3287,11 +3287,8 @@ func Zero(typ Type) Value {
        return Value{t, nil, fl}
 }
 
-// must match declarations in runtime/map.go.
-const maxZero = 1024
-
 //go:linkname zeroVal runtime.zeroVal
-var zeroVal [maxZero]byte
+var zeroVal [abi.ZeroValSize]byte
 
 // New returns a Value representing a pointer to a new zero value
 // for the specified type. That is, the returned Value's Type is PointerTo(typ).
index 6f5623b1029bfbc44c0110655ca62750ed2f5d71..7048949073f407328ac3ecc43666030cc90c03cd 100644 (file)
@@ -1436,8 +1436,7 @@ func reflectlite_maplen(h *hmap) int {
        return h.count
 }
 
-const maxZero = 1024 // must match value in reflect/value.go:maxZero cmd/compile/internal/gc/walk.go:zeroValSize
-var zeroVal [maxZero]byte
+var zeroVal [abi.ZeroValSize]byte
 
 // mapinitnoop is a no-op function known the Go linker; if a given global
 // map (of the right size) is determined to be dead, the linker will