aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/html/template/html.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/html/template/html.go')
-rw-r--r--libgo/go/html/template/html.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/libgo/go/html/template/html.go b/libgo/go/html/template/html.go
index 2ea5a7d..13a0cd0 100644
--- a/libgo/go/html/template/html.go
+++ b/libgo/go/html/template/html.go
@@ -137,7 +137,7 @@ var htmlNospaceNormReplacementTable = []string{
// htmlReplacer returns s with runes replaced according to replacementTable
// and when badRunes is true, certain bad runes are allowed through unescaped.
func htmlReplacer(s string, replacementTable []string, badRunes bool) string {
- written, b := 0, new(bytes.Buffer)
+ written, b := 0, new(strings.Builder)
r, w := rune(0), 0
for i := 0; i < len(s); i += w {
// Cannot use 'for range s' because we need to preserve the width
@@ -146,6 +146,9 @@ func htmlReplacer(s string, replacementTable []string, badRunes bool) string {
r, w = utf8.DecodeRuneInString(s[i:])
if int(r) < len(replacementTable) {
if repl := replacementTable[r]; len(repl) != 0 {
+ if written == 0 {
+ b.Grow(len(s))
+ }
b.WriteString(s[written:i])
b.WriteString(repl)
written = i + w
@@ -154,6 +157,9 @@ func htmlReplacer(s string, replacementTable []string, badRunes bool) string {
// No-op.
// IE does not allow these ranges in unquoted attrs.
} else if 0xfdd0 <= r && r <= 0xfdef || 0xfff0 <= r && r <= 0xffff {
+ if written == 0 {
+ b.Grow(len(s))
+ }
fmt.Fprintf(b, "%s&#x%x;", s[written:i], r)
written = i + w
}