Avoid allocating []byte for every written newline This shaves off another ~25% of allocs.
Vytautas Ĺ altenis vytas@rtfb.lt
Sat, 08 Oct 2016 18:17:00 +0300
1 files changed,
8 insertions(+),
7 deletions(-)
jump to
M
html.go
→
html.go
@@ -314,11 +314,6 @@ }
return attrs } -var ( - gtBytes = []byte{'>'} - spaceBytes = []byte{' '} -) - func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) { w.Write(name) if len(attrs) > 0 {@@ -385,9 +380,15 @@ }
func (r *HTMLRenderer) cr(w io.Writer) { if r.lastOutputLen > 0 { - r.out(w, []byte{'\n'}) + r.out(w, nlBytes) } } + +var ( + nlBytes = []byte{'\n'} + gtBytes = []byte{'>'} + spaceBytes = []byte{' '} +) var ( brTag = []byte("<br>")@@ -504,7 +505,7 @@ escapeHTML(w, node.Literal)
} } case Softbreak: - r.out(w, []byte{'\n'}) + r.cr(w) // TODO: make it configurable via out(renderer.softbreak) case Hardbreak: if r.Flags&UseXHTML == 0 {