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:
parent
851ecea4cc
commit
036bc38d83
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user