all repos — grayfriday @ c60ee1aab0808d19e60ad53500ff9a7ac3dfd3d2

blackfriday fork with a few changes

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
commit

c60ee1aab0808d19e60ad53500ff9a7ac3dfd3d2

parent

461803619bb97f3b6e50248dccae978ca17f8d27

1 files changed, 8 insertions(+), 7 deletions(-)

jump to
M html.gohtml.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 {