Skip to content

Commit 2a765b2

Browse files
committed
Hint the compiler to remove bounds checks inside {%u %}
1 parent 8de777e commit 2a765b2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

urlencode.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package quicktemplate
22

33
func appendURLEncode(dst []byte, src string) []byte {
4-
for i, n := 0, len(src); i < n; i++ {
4+
n := len(src)
5+
if n > 0 {
6+
// Hint the compiler to remove bounds checks in the loop below.
7+
_ = src[n-1]
8+
}
9+
for i := 0; i < n; i++ {
510
c := src[i]
611

712
// See http://www.w3.org/TR/html5/forms.html#form-submission-algorithm

0 commit comments

Comments
 (0)