Skip to content

Commit 5ddb209

Browse files
author
Iskander Sharipov
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 05166bf commit 5ddb209

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

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

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,14 +1719,14 @@ func typecheck1(n *Node, top int) *Node {
17191719
}
17201720
}
17211721

1722-
// do not use stringtoarraylit.
1722+
// do not convert to []byte literal. See CL 125796.
17231723
// generated code and compiler memory footprint is better without it.
17241724
case OSTRARRAYBYTE:
17251725
break
17261726

17271727
case OSTRARRAYRUNE:
17281728
if n.Left.Op == OLITERAL {
1729-
n = stringtoarraylit(n)
1729+
n = stringtoruneslit(n)
17301730
}
17311731
}
17321732

@@ -3509,27 +3509,19 @@ func typecheckfunc(n *Node) {
35093509
}
35103510
}
35113511

3512-
// The result of stringtoarraylit MUST be assigned back to n, e.g.
3513-
// n.Left = stringtoarraylit(n.Left)
3514-
func stringtoarraylit(n *Node) *Node {
3512+
// The result of stringtoruneslit MUST be assigned back to n, e.g.
3513+
// n.Left = stringtoruneslit(n.Left)
3514+
func stringtoruneslit(n *Node) *Node {
35153515
if n.Left.Op != OLITERAL || n.Left.Val().Ctype() != CTSTR {
35163516
Fatalf("stringtoarraylit %v", n)
35173517
}
35183518

3519-
s := n.Left.Val().U.(string)
35203519
var l []*Node
3521-
if n.Type.Elem().Etype == TUINT8 {
3522-
// []byte
3523-
for i := 0; i < len(s); i++ {
3524-
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(s[0]))))
3525-
}
3526-
} else {
3527-
// []rune
3528-
i := 0
3529-
for _, r := range s {
3530-
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
3531-
i++
3532-
}
3520+
s := n.Left.Val().U.(string)
3521+
i := 0
3522+
for _, r := range s {
3523+
l = append(l, nod(OKEY, nodintconst(int64(i)), nodintconst(int64(r))))
3524+
i++
35333525
}
35343526

35353527
nn := nod(OCOMPLIT, nil, typenod(n.Type))

0 commit comments

Comments
 (0)