diff options
Diffstat (limited to 'src/html/template/js.go')
| -rw-r--r-- | src/html/template/js.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/html/template/js.go b/src/html/template/js.go index 872f6786b3..04c7c325db 100644 --- a/src/html/template/js.go +++ b/src/html/template/js.go @@ -187,7 +187,7 @@ func jsValEscaper(args ...interface{}) string { } first, _ := utf8.DecodeRune(b) last, _ := utf8.DecodeLastRune(b) - var buf bytes.Buffer + var buf strings.Builder // Prevent IdentifierNames and NumericLiterals from running into // keywords: in, instanceof, typeof, void pad := isJSIdentPart(first) || isJSIdentPart(last) @@ -217,7 +217,7 @@ func jsValEscaper(args ...interface{}) string { if pad { buf.WriteByte(' ') } - b = buf.Bytes() + return buf.String() } return string(b) } @@ -253,7 +253,7 @@ func jsRegexpEscaper(args ...interface{}) string { // It also replaces runes U+2028 and U+2029 with the raw strings `\u2028` and // `\u2029`. func replace(s string, replacementTable []string) string { - var b bytes.Buffer + var b strings.Builder r, w, written := rune(0), 0, 0 for i := 0; i < len(s); i += w { // See comment in htmlEscaper. @@ -269,6 +269,9 @@ func replace(s string, replacementTable []string) string { default: continue } + if written == 0 { + b.Grow(len(s)) + } b.WriteString(s[written:i]) b.WriteString(repl) written = i + w |
