]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: lazily initialize litbuf
authorMatthew Dempsky <mdempsky@google.com>
Tue, 26 Apr 2016 17:55:32 +0000 (10:55 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 26 Apr 2016 22:49:54 +0000 (22:49 +0000)
Instead of eagerly creating strings like "literal 2.01" for every
lexed number in case we need to mention it in an error message, defer
this work to (*parser).syntax_error.

name      old allocs/op  new allocs/op  delta
Template      482k ± 0%      482k ± 0%  -0.12%   (p=0.000 n=9+10)
GoTypes      1.35M ± 0%     1.35M ± 0%  -0.04%  (p=0.015 n=10+10)
Compiler     5.45M ± 0%     5.44M ± 0%  -0.12%    (p=0.000 n=9+8)

Change-Id: I333b3c80e583864914412fb38f8c0b7f1d8c8821
Reviewed-on: https://go-review.googlesource.com/22480
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/parser.go

index 09fed98985d392f5ea312870bd4da5288d9b2696..8608a6229c922177a6a5c404be9bf6e9bf457307 100644 (file)
@@ -755,7 +755,7 @@ func (l *lexer) number(c rune) {
        }
 
 done:
-       litbuf = "literal " + str
+       litbuf = "" // lazily initialized in (*parser).syntax_error
        l.nlsemi = true
        l.tok = LLITERAL
 }
index 97a18497ff826a4f0e4a6325108d0e2285f0283a..55f352590bb35100e3a3fc7fff4f674f421e20cf 100644 (file)
@@ -102,6 +102,9 @@ func (p *parser) syntax_error(msg string) {
                        tok = "name"
                }
        case LLITERAL:
+               if litbuf == "" {
+                       litbuf = "literal " + lexbuf.String()
+               }
                tok = litbuf
        case LOPER:
                tok = goopnames[p.op]