]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: remove strbyteseql
authorMatthew Dempsky <mdempsky@google.com>
Fri, 9 Sep 2016 18:28:07 +0000 (11:28 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 9 Sep 2016 19:25:56 +0000 (19:25 +0000)
cmd/compile already optimizes "string(b) == s" to avoid allocating a
temporary string.

Change-Id: I4244fbeae8d350261494135c357f9a6e2ab7ace3
Reviewed-on: https://go-review.googlesource.com/28931
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/syntax/scanner.go

index e78950ad1a4cf35c2c7ec40dd379e0a1298fa306..b84fcc5fd16d8ad27369f752f89b2b6a91314ad1 100644 (file)
@@ -317,7 +317,7 @@ func (s *scanner) ident() {
 
        // possibly a keyword
        if len(lit) >= 2 {
-               if tok := keywordMap[hash(lit)]; tok != 0 && strbyteseql(tokstrings[tok], lit) {
+               if tok := keywordMap[hash(lit)]; tok != 0 && tokstrings[tok] == string(lit) {
                        s.nlsemi = contains(1<<_Break|1<<_Continue|1<<_Fallthrough|1<<_Return, tok)
                        s.tok = tok
                        return
@@ -347,18 +347,6 @@ func hash(s []byte) uint {
        return (uint(s[0])<<4 ^ uint(s[1]) + uint(len(s))) & uint(len(keywordMap)-1)
 }
 
-func strbyteseql(s string, b []byte) bool {
-       if len(s) == len(b) {
-               for i, b := range b {
-                       if s[i] != b {
-                               return false
-                       }
-               }
-               return true
-       }
-       return false
-}
-
 var keywordMap [1 << 6]token // size must be power of two
 
 func init() {