]> Cypherpunks repositories - gostls13.git/commit
text/template/parse: make atTerminator more efficient
authorRob Pike <r@golang.org>
Sun, 15 May 2022 03:14:49 +0000 (13:14 +1000)
committerRob Pike <r@golang.org>
Mon, 16 May 2022 21:02:09 +0000 (21:02 +0000)
commit053b63cfb56f574fd216166020066f3b48d5d878
treec6e78cb0ab9cc0205b5dfb53379649c569623621
parenta8facc456f07574b802c61b11140a77e8ac93c2a
text/template/parse: make atTerminator more efficient

The change https://go.dev/cl/398475 was too complicated and expensive.
Since the whole string is always available, all that's needed
is a call to strings.HasPrefix.

While we're here, change the way lexer.backup works
so it can be called repeatedly to back up more than one
rune, in case that becomes necessary. This change also
requires less state to maintain, as lexer.width was only
there for backup, and prevented multiple steps.

Fixes #52191

Change-Id: I43b64fc66edeb8ba73ba5aa72f3b727c377dc067
Reviewed-on: https://go-review.googlesource.com/c/go/+/406476
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/text/template/parse/lex.go