Commit 980a57a8 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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 <josharian@gmail.com>
Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f0e97546
......@@ -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)
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment