diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2015-02-24 20:54:57 +0000 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2015-02-26 01:46:16 +0000 |
commit | 9f4c25e2236617c27e5b430c774b4d9c4b86ba1b (patch) | |
tree | 55e6c6df2e163abc7d852c9b70751b2f4f94bb10 | |
parent | 1d4bfb3ebb1cbe3807c8623cf8ad594346c80cc3 (diff) | |
download | go-git-9f4c25e2236617c27e5b430c774b4d9c4b86ba1b.tar.gz |
cmd/gc: reduce lexer allocs when parsing numeric constants
This reduces the number of allocs when
running the rotate.go tests by
about 20%, after applying CL 5700.
Combining
s = "const str"
s += <another string>
generally saves an alloc and might be a candidate for
rsc's grind tool. However, I'm sending this CL now
because this also reuses the result of calling lexbuf.String.
Change-Id: If3a7300b7da9612ab62bb910ee90349dca88dde3
Reviewed-on: https://go-review.googlesource.com/5821
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/cmd/internal/gc/lex.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/cmd/internal/gc/lex.go b/src/cmd/internal/gc/lex.go index 19b969e57f..55c8d76bc2 100644 --- a/src/cmd/internal/gc/lex.go +++ b/src/cmd/internal/gc/lex.go @@ -853,6 +853,7 @@ func _yylex(yylval *yySymType) int32 { var rune_ uint var s *Sym var h *Loophack + var str string prevlineno = lineno @@ -1405,8 +1406,9 @@ ncu: cp = nil ungetc(c) + str = lexbuf.String() yylval.val.U.Xval = new(Mpint) - mpatofix(yylval.val.U.Xval, lexbuf.String()) + mpatofix(yylval.val.U.Xval, str) if yylval.val.U.Xval.Ovf != 0 { Yyerror("overflow in constant") Mpmovecfix(yylval.val.U.Xval, 0) @@ -1416,8 +1418,7 @@ ncu: if Debug['x'] != 0 { fmt.Printf("lex: integer literal\n") } - litbuf = "literal " - litbuf += lexbuf.String() + litbuf = "literal " + str return LLITERAL casedot: @@ -1461,9 +1462,10 @@ caseep: casei: cp = nil + str = lexbuf.String() yylval.val.U.Cval = new(Mpcplx) Mpmovecflt(&yylval.val.U.Cval.Real, 0.0) - mpatoflt(&yylval.val.U.Cval.Imag, lexbuf.String()) + mpatoflt(&yylval.val.U.Cval.Imag, str) if yylval.val.U.Cval.Imag.Val.Ovf != 0 { Yyerror("overflow in imaginary constant") Mpmovecflt(&yylval.val.U.Cval.Real, 0.0) @@ -1473,16 +1475,16 @@ casei: if Debug['x'] != 0 { fmt.Printf("lex: imaginary literal\n") } - litbuf = "literal " - litbuf += lexbuf.String() + litbuf = "literal " + str return LLITERAL caseout: cp = nil ungetc(c) + str = lexbuf.String() yylval.val.U.Fval = new(Mpflt) - mpatoflt(yylval.val.U.Fval, lexbuf.String()) + mpatoflt(yylval.val.U.Fval, str) if yylval.val.U.Fval.Val.Ovf != 0 { Yyerror("overflow in float constant") Mpmovecflt(yylval.val.U.Fval, 0.0) @@ -1492,8 +1494,7 @@ caseout: if Debug['x'] != 0 { fmt.Printf("lex: floating literal\n") } - litbuf = "literal " - litbuf += lexbuf.String() + litbuf = "literal " + str return LLITERAL strlit: |