Commit 5ddb2091 authored by Iskander Sharipov's avatar Iskander Sharipov

cmd/compile/internal/gc: remove dead code from stringtoarraylit

The code path for []byte is unused.
Rename function to stringtoruneslit to reflect change in the behavior.

Note that removed code had a bug in it,
it used [0] index instead of [i] inside a loop body.

Change-Id: I58ece5d9d3835887b014446f8a7d3e7fc2fdcaa3
Reviewed-on: https://go-review.googlesource.com/c/125796
Run-TryBot: Iskander Sharipov <iskander.sharipov@intel.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 05166bf5
...@@ -1719,14 +1719,14 @@ func typecheck1(n *Node, top int) *Node { ...@@ -1719,14 +1719,14 @@ func typecheck1(n *Node, top int) *Node {
} }
} }
// do not use stringtoarraylit. // do not convert to []byte literal. See CL 125796.
// generated code and compiler memory footprint is better without it. // generated code and compiler memory footprint is better without it.
case OSTRARRAYBYTE: case OSTRARRAYBYTE:
break break
case OSTRARRAYRUNE: case OSTRARRAYRUNE:
if n.Left.Op == OLITERAL { if n.Left.Op == OLITERAL {
n = stringtoarraylit(n) n = stringtoruneslit(n)
} }
} }
...@@ -3509,27 +3509,19 @@ func typecheckfunc(n *Node) { ...@@ -3509,27 +3509,19 @@ func typecheckfunc(n *Node) {
} }
} }
// The result of stringtoarraylit MUST be assigned back to n, e.g. // The result of stringtoruneslit MUST be assigned back to n, e.g.
// n.Left = stringtoarraylit(n.Left) // n.Left = stringtoruneslit(n.Left)
func stringtoarraylit(n *Node) *Node { func stringtoruneslit(n *Node) *Node {
if n.Left.Op != OLITERAL || n.Left.Val().Ctype() != CTSTR { if n.Left.Op != OLITERAL || n.Left.Val().Ctype() != CTSTR {
Fatalf("stringtoarraylit %v", n) Fatalf("stringtoarraylit %v", n)
} }
s := n.Left.Val().U.(string)
var l []*Node var l []*Node
if n.Type.Elem().Etype == TUINT8 { s := n.Left.Val().U.(string)
// []byte i := 0
for i := 0; i < len(s); i++ { for _, r := range s {
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(s[0])))) l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
} i++
} else {
// []rune
i := 0
for _, r := range s {
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
i++
}
} }
nn := nod(OCOMPLIT, nil, typenod(n.Type)) nn := nod(OCOMPLIT, nil, typenod(n.Type))
......
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