mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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
This commit is contained in:
parent
d9b82baac1
commit
3fc327b33b
4 changed files with 110 additions and 67 deletions
|
|
@ -1374,7 +1374,7 @@ func (c *typeConv) Struct(dt *dwarf.StructType) (expr *ast.StructType, csyntax s
|
|||
|
||||
if !*godefs && !*cdefs {
|
||||
for cid, goid := range ident {
|
||||
if token.Lookup([]byte(goid)).IsKeyword() {
|
||||
if token.Lookup(goid).IsKeyword() {
|
||||
// Avoid keyword
|
||||
goid = "_" + goid
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue