1
0
mirror of https://github.com/golang/go synced 2024-11-18 03:44:46 -07:00

cmd/compile/internal/gc: avoid stringsCompare for string literals

Passes go build -a -toolexec 'toolstash -cmp' std cmp.

Change-Id: I7567355d405c976c5d91a0cd4e9486ebeb348dbb
Reviewed-on: https://go-review.googlesource.com/14682
Reviewed-by: Dave Cheney <dave@cheney.net>
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Håvard Haugen 2015-09-17 21:01:29 +02:00 committed by Brad Fitzpatrick
parent f482a0f023
commit eddd7ff3cd
2 changed files with 10 additions and 9 deletions

View File

@ -986,37 +986,37 @@ func evconst(n *Node) {
goto setfalse goto setfalse
case OEQ<<16 | CTSTR: case OEQ<<16 | CTSTR:
if cmpslit(nl, nr) == 0 { if strlit(nl) == strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
case ONE<<16 | CTSTR: case ONE<<16 | CTSTR:
if cmpslit(nl, nr) != 0 { if strlit(nl) != strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
case OLT<<16 | CTSTR: case OLT<<16 | CTSTR:
if cmpslit(nl, nr) < 0 { if strlit(nl) < strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
case OLE<<16 | CTSTR: case OLE<<16 | CTSTR:
if cmpslit(nl, nr) <= 0 { if strlit(nl) <= strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
case OGE<<16 | CTSTR: case OGE<<16 | CTSTR:
if cmpslit(nl, nr) >= 0 { if strlit(nl) >= strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
case OGT<<16 | CTSTR: case OGT<<16 | CTSTR:
if cmpslit(nl, nr) > 0 { if strlit(nl) > strlit(nr) {
goto settrue goto settrue
} }
goto setfalse goto setfalse
@ -1341,8 +1341,9 @@ func defaultlit2(lp **Node, rp **Node, force int) {
Convlit(rp, Types[TINT]) Convlit(rp, Types[TINT])
} }
func cmpslit(l, r *Node) int { // strlit returns the value of a literal string Node as a string.
return stringsCompare(l.Val().U.(string), r.Val().U.(string)) func strlit(n *Node) string {
return n.Val().U.(string)
} }
func Smallintconst(n *Node) bool { func Smallintconst(n *Node) bool {

View File

@ -1356,7 +1356,7 @@ func walkexpr(np **Node, init **NodeList) {
} }
// s + "badgerbadgerbadger" == "badgerbadgerbadger" // s + "badgerbadgerbadger" == "badgerbadgerbadger"
if (n.Etype == OEQ || n.Etype == ONE) && Isconst(n.Right, CTSTR) && n.Left.Op == OADDSTR && count(n.Left.List) == 2 && Isconst(n.Left.List.Next.N, CTSTR) && cmpslit(n.Right, n.Left.List.Next.N) == 0 { if (n.Etype == OEQ || n.Etype == ONE) && Isconst(n.Right, CTSTR) && n.Left.Op == OADDSTR && count(n.Left.List) == 2 && Isconst(n.Left.List.Next.N, CTSTR) && strlit(n.Right) == strlit(n.Left.List.Next.N) {
r := Nod(int(n.Etype), Nod(OLEN, n.Left.List.N, nil), Nodintconst(0)) r := Nod(int(n.Etype), Nod(OLEN, n.Left.List.N, nil), Nodintconst(0))
typecheck(&r, Erv) typecheck(&r, Erv)
walkexpr(&r, init) walkexpr(&r, init)