mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: replace Ctype switches with type switches
Instead of switching on Ctype (which internally uses a type switch) and then scattering lots of type assertions throughout the CTFOO case clauses, just use type switches directly on the underlying constant value. Passes toolstash/buildall. Change-Id: I9bc172cc67e5f391cddc15539907883b4010689e Reviewed-on: https://go-review.googlesource.com/22384 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
2d342fba78
commit
97360096e5
9 changed files with 146 additions and 168 deletions
|
|
@ -1309,28 +1309,22 @@ func addvalue(p *InitPlan, xoffset int64, n *Node) {
|
|||
func iszero(n *Node) bool {
|
||||
switch n.Op {
|
||||
case OLITERAL:
|
||||
switch n.Val().Ctype() {
|
||||
switch u := n.Val().U.(type) {
|
||||
default:
|
||||
Dump("unexpected literal", n)
|
||||
Fatalf("iszero")
|
||||
|
||||
case CTNIL:
|
||||
case *NilVal:
|
||||
return true
|
||||
|
||||
case CTSTR:
|
||||
return n.Val().U.(string) == ""
|
||||
|
||||
case CTBOOL:
|
||||
return !n.Val().U.(bool)
|
||||
|
||||
case CTINT, CTRUNE:
|
||||
return n.Val().U.(*Mpint).CmpInt64(0) == 0
|
||||
|
||||
case CTFLT:
|
||||
return n.Val().U.(*Mpflt).CmpFloat64(0) == 0
|
||||
|
||||
case CTCPLX:
|
||||
return n.Val().U.(*Mpcplx).Real.CmpFloat64(0) == 0 && n.Val().U.(*Mpcplx).Imag.CmpFloat64(0) == 0
|
||||
case string:
|
||||
return u == ""
|
||||
case bool:
|
||||
return !u
|
||||
case *Mpint:
|
||||
return u.CmpInt64(0) == 0
|
||||
case *Mpflt:
|
||||
return u.CmpFloat64(0) == 0
|
||||
case *Mpcplx:
|
||||
return u.Real.CmpFloat64(0) == 0 && u.Imag.CmpFloat64(0) == 0
|
||||
}
|
||||
|
||||
case OARRAYLIT:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue