1
0
mirror of https://github.com/golang/go synced 2024-11-24 01:30:10 -07:00

go/token: a little performance improvement for IsIdentifier function

This commit is contained in:
chanxuehong 2021-09-22 15:47:15 +08:00
parent 851ecea4cc
commit 036bc38d83

View File

@ -340,10 +340,13 @@ func IsKeyword(name string) bool {
// is not a digit. Keywords are not identifiers.
//
func IsIdentifier(name string) bool {
if name == "" || IsKeyword(name) {
return false
}
for i, c := range name {
if !unicode.IsLetter(c) && c != '_' && (i == 0 || !unicode.IsDigit(c)) {
return false
}
}
return name != "" && !IsKeyword(name)
return true
}