mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: remove strbyteseql
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>
This commit is contained in:
parent
3877f820a6
commit
cfc0d6d884
1 changed files with 1 additions and 13 deletions
|
|
@ -317,7 +317,7 @@ func (s *scanner) ident() {
|
||||||
|
|
||||||
// possibly a keyword
|
// possibly a keyword
|
||||||
if len(lit) >= 2 {
|
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.nlsemi = contains(1<<_Break|1<<_Continue|1<<_Fallthrough|1<<_Return, tok)
|
||||||
s.tok = tok
|
s.tok = tok
|
||||||
return
|
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)
|
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
|
var keywordMap [1 << 6]token // size must be power of two
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue