]> Cypherpunks repositories - gostls13.git/commit
text/template: efficient reporting of line numbers
authorRob Pike <r@golang.org>
Tue, 8 Nov 2016 23:43:20 +0000 (15:43 -0800)
committerRob Pike <r@golang.org>
Tue, 15 Nov 2016 00:42:33 +0000 (00:42 +0000)
commit24a088d20ad52c527f61b34217da72589e366833
tree5400091cdd90194a3ebf2631349fa481f4b64926
parentbb00a8d97faa70bf7a1cbdd4a43e95347a9c8709
text/template: efficient reporting of line numbers

Instead of scanning the text to count newlines, which is n², keep track as we go
and store the line number in the token.

benchmark                 old ns/op      new ns/op     delta
BenchmarkParseLarge-4     1589721293     38783310      -97.56%

Fixes #17851

Change-Id: I231225c61e667535e2ce55cd2facea6d279cc59d
Reviewed-on: https://go-review.googlesource.com/33234
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/text/template/exec_test.go
src/text/template/parse/lex.go
src/text/template/parse/lex_test.go
src/text/template/parse/parse.go
src/text/template/parse/parse_test.go