]> Cypherpunks repositories - gostls13.git/commit
go/scanner: 17% faster scanning
authorRobert Griesemer <gri@golang.org>
Wed, 11 Jan 2012 22:20:32 +0000 (14:20 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 11 Jan 2012 22:20:32 +0000 (14:20 -0800)
commit3fc327b33bede4445ff01072b8cc91c88fbd10fa
tree2faafcdd466841e75fc2e906ec88f39d9b18508f
parentd9b82baac1f25fce52d1a392fb39711fa9462f40
go/scanner: 17% faster scanning

- Changed the Scan API semantics slightly:
The token literal string is only returned
if the token is a literal, comment, semicolon,
or illegal character. In all other cases, the
token literal value is determined by the token
value.

Clients that care about the token literal value
when not present can always use the following
piece of code:

pos, tok, lit := scanner.Scan()
if lit == "" {
   lit = tok.String()
}

- Changed token.Lookup API to use a string instead
of a []byte argument.

- Both these changes were long-standing TODOs.

- Added BenchmarkScan.

This change permits a faster implementation of Scan
with much fewer string creations:

benchmark                old ns/op    new ns/op    delta
scanner.BenchmarkScan        74404        61457  -17.40%

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5532076
src/cmd/cgo/gcc.go
src/pkg/go/scanner/scanner.go
src/pkg/go/scanner/scanner_test.go
src/pkg/go/token/token.go