From: Josh Bleecher Snyder Date: Tue, 23 Apr 2019 00:04:59 +0000 (-0700) Subject: cmd/compile: clean up string/bytes/runes conversion code X-Git-Tag: go1.13beta1~596 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=980a57a84b932b43fc2d3ab699f7c235472009ab;p=gostls13.git cmd/compile: clean up string/bytes/runes conversion code Combine the OBYTES2STR and ORUNES2STR cases, as they are identical. Clean up the construction, commenting, and spacing of the other cases, and make them all match. Passes toolstash-check. Change-Id: I1be8a528927caeb15e49cb12ca0f11c0827dadd9 Reviewed-on: https://go-review.googlesource.com/c/go/+/173322 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Matthew Dempsky TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index be4f9ab5c0..837efbaf91 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1355,50 +1355,36 @@ opswitch: a := nodnil() if n.Esc == EscNone { t := types.NewArray(types.Types[TUINT8], 4) - var_ := temp(t) - a = nod(OADDR, var_, nil) + a = nod(OADDR, temp(t), nil) } - // intstring(*[4]byte, rune) n = mkcall("intstring", n.Type, init, a, conv(n.Left, types.Types[TINT64])) - case OBYTES2STR: + case OBYTES2STR, ORUNES2STR: a := nodnil() if n.Esc == EscNone { // Create temporary buffer for string on stack. t := types.NewArray(types.Types[TUINT8], tmpstringbufsize) - a = nod(OADDR, temp(t), nil) } + fn := "slicebytetostring" + if n.Op == ORUNES2STR { + fn = "slicerunetostring" + } + // slicebytetostring(*[32]byte, []byte) string + // slicerunetostring(*[32]byte, []rune) string + n = mkcall(fn, n.Type, init, a, n.Left) - // slicebytetostring(*[32]byte, []byte) string; - n = mkcall("slicebytetostring", n.Type, init, a, n.Left) - - // slicebytetostringtmp([]byte) string; case OBYTES2STRTMP: n.Left = walkexpr(n.Left, init) - if !instrumenting { // Let the backend handle OBYTES2STRTMP directly // to avoid a function call to slicebytetostringtmp. break } - + // slicebytetostringtmp([]byte) string n = mkcall("slicebytetostringtmp", n.Type, init, n.Left) - // slicerunetostring(*[32]byte, []rune) string; - case ORUNES2STR: - a := nodnil() - - if n.Esc == EscNone { - // Create temporary buffer for string on stack. - t := types.NewArray(types.Types[TUINT8], tmpstringbufsize) - - a = nod(OADDR, temp(t), nil) - } - - n = mkcall("slicerunetostring", n.Type, init, a, n.Left) - case OSTR2BYTES: s := n.Left if Isconst(s, CTSTR) { @@ -1431,16 +1417,14 @@ opswitch: n = walkexpr(n, init) break } - a := nodnil() + a := nodnil() if n.Esc == EscNone { // Create temporary buffer for slice on stack. t := types.NewArray(types.Types[TUINT8], tmpstringbufsize) - a = nod(OADDR, temp(t), nil) } - - // stringtoslicebyte(*32[byte], string) []byte; + // stringtoslicebyte(*32[byte], string) []byte n = mkcall("stringtoslicebyte", n.Type, init, a, conv(s, types.Types[TSTRING])) case OSTR2BYTESTMP: @@ -1453,17 +1437,14 @@ opswitch: // for i, c := range []byte(string) n.Left = walkexpr(n.Left, init) - // stringtoslicerune(*[32]rune, string) []rune case OSTR2RUNES: a := nodnil() - if n.Esc == EscNone { // Create temporary buffer for slice on stack. t := types.NewArray(types.Types[TINT32], tmpstringbufsize) - a = nod(OADDR, temp(t), nil) } - + // stringtoslicerune(*[32]rune, string) []rune n = mkcall("stringtoslicerune", n.Type, init, a, conv(n.Left, types.Types[TSTRING])) case OARRAYLIT, OSLICELIT, OMAPLIT, OSTRUCTLIT, OPTRLIT: @@ -2536,7 +2517,6 @@ func addstr(n *Node, init *Nodes) *Node { if sz < tmpstringbufsize { // Create temporary buffer for result string on stack. t := types.NewArray(types.Types[TUINT8], tmpstringbufsize) - buf = nod(OADDR, temp(t), nil) } }