]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: avoid stringsCompare for string literals
authorHÃ¥vard Haugen <havard.haugen@gmail.com>
Thu, 17 Sep 2015 19:01:29 +0000 (21:01 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 18 Sep 2015 00:23:34 +0000 (00:23 +0000)
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>
src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/gc/walk.go

index a6428ac4279f979e984722150d3372b577c2f81b..e7559c206e5a0490d7ddb485544f4fbb80c6d5f6 100644 (file)
@@ -986,37 +986,37 @@ func evconst(n *Node) {
                goto setfalse
 
        case OEQ<<16 | CTSTR:
-               if cmpslit(nl, nr) == 0 {
+               if strlit(nl) == strlit(nr) {
                        goto settrue
                }
                goto setfalse
 
        case ONE<<16 | CTSTR:
-               if cmpslit(nl, nr) != 0 {
+               if strlit(nl) != strlit(nr) {
                        goto settrue
                }
                goto setfalse
 
        case OLT<<16 | CTSTR:
-               if cmpslit(nl, nr) < 0 {
+               if strlit(nl) < strlit(nr) {
                        goto settrue
                }
                goto setfalse
 
        case OLE<<16 | CTSTR:
-               if cmpslit(nl, nr) <= 0 {
+               if strlit(nl) <= strlit(nr) {
                        goto settrue
                }
                goto setfalse
 
        case OGE<<16 | CTSTR:
-               if cmpslit(nl, nr) >= 0 {
+               if strlit(nl) >= strlit(nr) {
                        goto settrue
                }
                goto setfalse
 
        case OGT<<16 | CTSTR:
-               if cmpslit(nl, nr) > 0 {
+               if strlit(nl) > strlit(nr) {
                        goto settrue
                }
                goto setfalse
@@ -1341,8 +1341,9 @@ func defaultlit2(lp **Node, rp **Node, force int) {
        Convlit(rp, Types[TINT])
 }
 
-func cmpslit(l, r *Node) int {
-       return stringsCompare(l.Val().U.(string), r.Val().U.(string))
+// strlit returns the value of a literal string Node as a string.
+func strlit(n *Node) string {
+       return n.Val().U.(string)
 }
 
 func Smallintconst(n *Node) bool {
index 4ce1db6241488227176827f11de0ab8cc2bc6ff9..2afa05c66af3b734bce869ab93907c233c9baf9d 100644 (file)
@@ -1356,7 +1356,7 @@ func walkexpr(np **Node, init **NodeList) {
                }
 
                // 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))
                        typecheck(&r, Erv)
                        walkexpr(&r, init)