aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-03-28 13:38:24 -0700
committerRobert Griesemer <gri@golang.org>2011-03-28 13:38:24 -0700
commit2796ac1466799973973661a9ef917501c0f8416c (patch)
tree50d19a34d86b08aaee24db76f01844f04ff12e99
parent0caa0c092384960e3f7bfd2a3f0ee9ca0cba18fa (diff)
downloadgo-2796ac1466799973973661a9ef917501c0f8416c.tar.gz
go-2796ac1466799973973661a9ef917501c0f8416c.zip
go/token: use array instead of map for token->string table
R=rsc CC=golang-dev https://golang.org/cl/4284070
-rw-r--r--src/pkg/go/token/token.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/pkg/go/token/token.go b/src/pkg/go/token/token.go
index 2a2d3ecc4f..a5f21df168 100644
--- a/src/pkg/go/token/token.go
+++ b/src/pkg/go/token/token.go
@@ -126,10 +126,7 @@ const (
)
-// At the moment we have no array literal syntax that lets us describe
-// the index for each element - use a map for now to make sure they are
-// in sync.
-var tokens = map[Token]string{
+var tokens = [...]string{
ILLEGAL: "ILLEGAL",
EOF: "EOF",
@@ -237,10 +234,14 @@ var tokens = map[Token]string{
// constant name (e.g. for the token IDENT, the string is "IDENT").
//
func (tok Token) String() string {
- if str, exists := tokens[tok]; exists {
- return str
+ s := ""
+ if 0 <= tok && tok < Token(len(tokens)) {
+ s = tokens[tok]
}
- return "token(" + strconv.Itoa(int(tok)) + ")"
+ if s == "" {
+ s = "token(" + strconv.Itoa(int(tok)) + ")"
+ }
+ return s
}