all repos — grayfriday @ 22a3e5b744f34ee53bd864384eedb821791d4951

blackfriday fork with a few changes

Avoid calling bytes.Split() in appendLanguageAttr

This avoids some allocs.
Vytautas Saltenis vytas@uber.com
Sat, 29 Oct 2016 12:09:34 +0300
commit

22a3e5b744f34ee53bd864384eedb821791d4951

parent

9357a8f949cba3a9472fe5baf0202041ac5a46fd

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

jump to
M html.gohtml.go

@@ -307,11 +307,14 @@ return pt != Link && pt != CodeBlock && pt != Code

} func appendLanguageAttr(attrs []string, info []byte) []string { - infoWords := bytes.Split(info, []byte("\t ")) - if len(infoWords) > 0 && len(infoWords[0]) > 0 { - attrs = append(attrs, fmt.Sprintf("class=\"language-%s\"", infoWords[0])) + if len(info) == 0 { + return attrs + } + endOfLang := bytes.IndexAny(info, "\t ") + if endOfLang < 0 { + endOfLang = len(info) } - return attrs + return append(attrs, fmt.Sprintf("class=\"language-%s\"", info[:endOfLang])) } func (r *HTMLRenderer) tag(w io.Writer, name []byte, attrs []string) {