mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
Avoid allocating []byte for every written newline
This shaves off another ~25% of allocs.
This commit is contained in:
parent
461803619b
commit
c60ee1aab0
15
html.go
15
html.go
|
@ -314,11 +314,6 @@ func appendLanguageAttr(attrs []string, info []byte) []string {
|
|||
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,10 +380,16 @@ func (r *HTMLRenderer) out(w io.Writer, text []byte) {
|
|||
|
||||
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>")
|
||||
brXHTMLTag = []byte("<br />")
|
||||
|
@ -504,7 +505,7 @@ func (r *HTMLRenderer) RenderNode(w io.Writer, node *Node, entering bool) WalkSt
|
|||
}
|
||||
}
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user