]> 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>
Mon, 14 Nov 2016 18:42:48 +0000 (18:42 +0000)
commit794fb71d9c1018c4beae1657baca5229e6a02ad0
treeed42cf89824429507619862f76f8fa42f77b72ed
parent2f76c1985fa8bbb0fb09af6600445b5c7d4d5cb4
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: Ieaf89a35e371b405ad92e38baa1e3fa98d18cfb4
Reviewed-on: https://go-review.googlesource.com/32923
Reviewed-by: Robert Griesemer <gri@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