Skip to content

Commit 36760ca

Browse files
committed
text/template/parse: simplify I/O in lexing
The concurrent model for delivering tokens was fine for pedagogy, but has caused a few problems as the package has evolved (that is, got more complicated). It's easy to eliminate it, simplifying or removing some of the hacks used to work around these prolems. The old lexer would deliver tokens over a channel to the parsing goroutine, and continue running until EOF. In this rewrite, we instead run the machine until a token is ready, and shut it down until the next token is needed. The mechanism is just to return nil as the state function, which requires a bit more threading of return values through the state functions but is not difficult. The change is modest. A couple of error messages change, but otherwise the change has no external effect. This is just an internal cleanup, long overdue. benchmark old ns/op new ns/op delta BenchmarkParseLarge-20 12222729 6769966 -44.61% BenchmarkVariableString-20 73.5 73.4 -0.16% BenchmarkListString-20 1827 1841 +0.77% benchmark old allocs new allocs delta BenchmarkVariableString-20 3 3 +0.00% BenchmarkListString-20 31 31 +0.00% benchmark old bytes new bytes delta BenchmarkVariableString-20 72 72 +0.00% BenchmarkListString-20 1473 1473 +0.00% Fixes #53261 Change-Id: I4133bed2f8df16d398b707fb9509230325765c57 Reviewed-on: https://go-review.googlesource.com/c/go/+/421883 Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent 3a067b2 commit 36760ca

File tree

4 files changed

+135
-136
lines changed

4 files changed

+135
-136
lines changed

0 commit comments

Comments
 (0)