]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: clean up string/bytes/runes conversion code
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 23 Apr 2019 00:04:59 +0000 (17:04 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 23 Apr 2019 02:14:40 +0000 (02:14 +0000)
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 <josharian@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/walk.go

index be4f9ab5c0386984f9a67816a0b259f42ff6cc25..837efbaf914ed0f5d22a910a614975503fe0f965 100644 (file)
@@ -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)
                }
        }