all repos — grayfriday @ df64ec5d0f636a9ade25c3a5046433d23d0d47c8

blackfriday fork with a few changes

allocate new buffers on stack; mild speed improvement
Russ Ross russ@dixie.edu
Tue, 31 May 2011 11:11:04 -0600
commit

df64ec5d0f636a9ade25c3a5046433d23d0d47c8

parent

9d23b68fa51d84855bbfaff1d12a449a53a25268

4 files changed, 57 insertions(+), 57 deletions(-)

jump to
M block.goblock.go

@@ -116,8 +116,8 @@ for end > 0 && (data[end-1] == ' ' || data[end-1] == '\t') {

end-- } if end > i { - work := bytes.NewBuffer(nil) - parseInline(work, rndr, data[i:end]) + var work bytes.Buffer + parseInline(&work, rndr, data[i:end]) if rndr.mk.Header != nil { rndr.mk.Header(out, work.Bytes(), level, rndr.mk.Opaque) }

@@ -450,7 +450,7 @@ if beg == 0 {

return 0 } - work := bytes.NewBuffer(nil) + var work bytes.Buffer for beg < len(data) { fence_end := isFencedCode(data[beg:], nil)

@@ -491,10 +491,10 @@ return beg

} func blockTable(out *bytes.Buffer, rndr *render, data []byte) int { - header_work := bytes.NewBuffer(nil) - i, columns, col_data := blockTableHeader(header_work, rndr, data) + var header_work bytes.Buffer + i, columns, col_data := blockTableHeader(&header_work, rndr, data) if i > 0 { - body_work := bytes.NewBuffer(nil) + var body_work bytes.Buffer for i < len(data) { pipes, row_start := 0, i

@@ -509,7 +509,7 @@ i = row_start

break } - blockTableRow(body_work, rndr, data[row_start:i], columns, col_data) + blockTableRow(&body_work, rndr, data[row_start:i], columns, col_data) i++ }

@@ -609,7 +609,7 @@ }

func blockTableRow(out *bytes.Buffer, rndr *render, data []byte, columns int, col_data []int) { i, col := 0, 0 - row_work := bytes.NewBuffer(nil) + var row_work bytes.Buffer if i < len(data) && data[i] == '|' { i++

@@ -632,15 +632,15 @@ for cell_end > cell_start && isspace(data[cell_end]) {

cell_end-- } - cell_work := bytes.NewBuffer(nil) - parseInline(cell_work, rndr, data[cell_start:cell_end+1]) + var cell_work bytes.Buffer + parseInline(&cell_work, rndr, data[cell_start:cell_end+1]) if rndr.mk.TableCell != nil { cdata := 0 if col < len(col_data) { cdata = col_data[col] } - rndr.mk.TableCell(row_work, cell_work.Bytes(), cdata, rndr.mk.Opaque) + rndr.mk.TableCell(&row_work, cell_work.Bytes(), cdata, rndr.mk.Opaque) } i++

@@ -653,7 +653,7 @@ cdata := 0

if col < len(col_data) { cdata = col_data[col] } - rndr.mk.TableCell(row_work, empty_cell, cdata, rndr.mk.Opaque) + rndr.mk.TableCell(&row_work, empty_cell, cdata, rndr.mk.Opaque) } }

@@ -679,8 +679,8 @@ }

// parse a blockquote fragment func blockQuote(out *bytes.Buffer, rndr *render, data []byte) int { - block := bytes.NewBuffer(nil) - work := bytes.NewBuffer(nil) + var block bytes.Buffer + var work bytes.Buffer beg, end := 0, 0 for beg < len(data) { for end = beg + 1; end < len(data) && data[end-1] != '\n'; end++ {

@@ -701,7 +701,7 @@ }

beg = end } - parseBlock(block, rndr, work.Bytes()) + parseBlock(&block, rndr, work.Bytes()) if rndr.mk.BlockQuote != nil { rndr.mk.BlockQuote(out, block.Bytes(), rndr.mk.Opaque) }

@@ -720,7 +720,7 @@ return 0

} func blockCode(out *bytes.Buffer, rndr *render, data []byte) int { - work := bytes.NewBuffer(nil) + var work bytes.Buffer beg, end := 0, 0 for beg < len(data) {

@@ -754,7 +754,7 @@ for len(workbytes) > n && workbytes[len(workbytes)-n-1] == '\n' {

n++ } if n > 0 { - work = bytes.NewBuffer(workbytes[:len(workbytes)-n]) + work.Truncate(len(workbytes)-n) } work.WriteByte('\n')

@@ -798,11 +798,11 @@ }

// parse ordered or unordered list block func blockList(out *bytes.Buffer, rndr *render, data []byte, flags int) int { - work := bytes.NewBuffer(nil) + var work bytes.Buffer i, j := 0, 0 for i < len(data) { - j = blockListItem(work, rndr, data[i:], &flags) + j = blockListItem(&work, rndr, data[i:], &flags) i += j if j == 0 || flags&LIST_ITEM_END_OF_LIST != 0 {

@@ -846,8 +846,8 @@ end++

} // get working buffers - work := bytes.NewBuffer(nil) - inter := bytes.NewBuffer(nil) + var work bytes.Buffer + var inter bytes.Buffer // put the first line into the working buffer work.Write(data[beg:end])

@@ -924,18 +924,18 @@ workbytes := work.Bytes()

if *flags&LIST_ITEM_CONTAINS_BLOCK != 0 { // intermediate render of block li if sublist > 0 && sublist < len(workbytes) { - parseBlock(inter, rndr, workbytes[:sublist]) - parseBlock(inter, rndr, workbytes[sublist:]) + parseBlock(&inter, rndr, workbytes[:sublist]) + parseBlock(&inter, rndr, workbytes[sublist:]) } else { - parseBlock(inter, rndr, workbytes) + parseBlock(&inter, rndr, workbytes) } } else { // intermediate render of inline li if sublist > 0 && sublist < len(workbytes) { - parseInline(inter, rndr, workbytes[:sublist]) - parseBlock(inter, rndr, workbytes[sublist:]) + parseInline(&inter, rndr, workbytes[:sublist]) + parseBlock(&inter, rndr, workbytes[sublist:]) } else { - parseInline(inter, rndr, workbytes) + parseInline(&inter, rndr, workbytes) } }

@@ -983,8 +983,8 @@ size--

} if level == 0 { - tmp := bytes.NewBuffer(nil) - parseInline(tmp, rndr, work[:size]) + var tmp bytes.Buffer + parseInline(&tmp, rndr, work[:size]) if rndr.mk.Paragraph != nil { rndr.mk.Paragraph(out, tmp.Bytes(), rndr.mk.Opaque) }

@@ -1004,8 +1004,8 @@ size--

} if size > 0 { - tmp := bytes.NewBuffer(nil) - parseInline(tmp, rndr, work[:size]) + var tmp bytes.Buffer + parseInline(&tmp, rndr, work[:size]) if rndr.mk.Paragraph != nil { rndr.mk.Paragraph(out, tmp.Bytes(), rndr.mk.Opaque) }

@@ -1017,8 +1017,8 @@ size = i

} } - header_work := bytes.NewBuffer(nil) - parseInline(header_work, rndr, work[:size]) + var header_work bytes.Buffer + parseInline(&header_work, rndr, work[:size]) if rndr.mk.Header != nil { rndr.mk.Header(out, header_work.Bytes(), level, rndr.mk.Opaque)
M inline.goinline.go

@@ -334,7 +334,7 @@

// find the reference if link_b == link_e { if text_has_nl { - b := bytes.NewBuffer(nil) + var b bytes.Buffer for j := 1; j < txt_e; j++ { switch {

@@ -371,7 +371,7 @@ var id []byte

// craft the id if text_has_nl { - b := bytes.NewBuffer(nil) + var b bytes.Buffer for j := 1; j < txt_e; j++ { switch {

@@ -403,19 +403,19 @@ i = txt_e + 1

} // build content: img alt is escaped, link content is parsed - content := bytes.NewBuffer(nil) + var content bytes.Buffer if txt_e > 1 { if isImg { content.Write(data[1:txt_e]) } else { - parseInline(content, rndr, data[1:txt_e]) + parseInline(&content, rndr, data[1:txt_e]) } } var u_link []byte if len(link) > 0 { - u_link_buf := bytes.NewBuffer(nil) - unescapeText(u_link_buf, link) + var u_link_buf bytes.Buffer + unescapeText(&u_link_buf, link) u_link = u_link_buf.Bytes() }

@@ -449,8 +449,8 @@

if end > 2 { switch { case rndr.mk.AutoLink != nil && altype != LINK_TYPE_NOT_AUTOLINK: - u_link := bytes.NewBuffer(nil) - unescapeText(u_link, data[1:end+1-2]) + var u_link bytes.Buffer + unescapeText(&u_link, data[1:end+1-2]) ret = rndr.mk.AutoLink(out, u_link.Bytes(), altype, rndr.mk.Opaque) case rndr.mk.RawHtmlTag != nil: ret = rndr.mk.RawHtmlTag(out, data[:end], rndr.mk.Opaque)

@@ -632,8 +632,8 @@ out.Truncate(len(out.Bytes()) - rewind)

} if rndr.mk.AutoLink != nil { - u_link := bytes.NewBuffer(nil) - unescapeText(u_link, data[:link_end]) + var u_link bytes.Buffer + unescapeText(&u_link, data[:link_end]) rndr.mk.AutoLink(out, u_link.Bytes(), LINK_TYPE_NORMAL, rndr.mk.Opaque) }

@@ -884,8 +884,8 @@ continue

} } - work := bytes.NewBuffer(nil) - parseInline(work, rndr, data[:i]) + var work bytes.Buffer + parseInline(&work, rndr, data[:i]) r := rndr.mk.Emphasis(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 1

@@ -918,8 +918,8 @@ }

i += length if i+1 < len(data) && data[i] == c && data[i+1] == c && i > 0 && !isspace(data[i-1]) { - work := bytes.NewBuffer(nil) - parseInline(work, rndr, data[:i]) + var work bytes.Buffer + parseInline(&work, rndr, data[:i]) r := render_method(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 2

@@ -952,9 +952,9 @@

switch { case (i+2 < len(data) && data[i+1] == c && data[i+2] == c && rndr.mk.TripleEmphasis != nil): // triple symbol found - work := bytes.NewBuffer(nil) + var work bytes.Buffer - parseInline(work, rndr, data[:i]) + parseInline(&work, rndr, data[:i]) r := rndr.mk.TripleEmphasis(out, work.Bytes(), rndr.mk.Opaque) if r > 0 { return i + 3
M markdown.gomarkdown.go

@@ -191,7 +191,7 @@ rndr.inline[':'] = inlineAutoLink

} // first pass: look for references, copy everything else - text := bytes.NewBuffer(nil) + var text bytes.Buffer beg, end := 0, 0 for beg < len(input) { // iterate over lines if end = isReference(rndr, input[beg:]); end > 0 {

@@ -204,7 +204,7 @@ }

// add the line body if present if end > beg { - expandTabs(text, input[beg:end]) + expandTabs(&text, input[beg:end]) } for end < len(input) && (input[end] == '\n' || input[end] == '\r') {

@@ -220,9 +220,9 @@ }

} // second pass: actual rendering - output := bytes.NewBuffer(nil) + var output bytes.Buffer if rndr.mk.DocumentHeader != nil { - rndr.mk.DocumentHeader(output, rndr.mk.Opaque) + rndr.mk.DocumentHeader(&output, rndr.mk.Opaque) } if text.Len() > 0 {

@@ -231,11 +231,11 @@ finalchar := text.Bytes()[text.Len()-1]

if finalchar != '\n' && finalchar != '\r' { text.WriteByte('\n') } - parseBlock(output, rndr, text.Bytes()) + parseBlock(&output, rndr, text.Bytes()) } if rndr.mk.DocumentFooter != nil { - rndr.mk.DocumentFooter(output, rndr.mk.Opaque) + rndr.mk.DocumentFooter(&output, rndr.mk.Opaque) } if rndr.nesting != 0 {
M smartypants.gosmartypants.go

@@ -332,8 +332,8 @@ options := opaque.(*htmlOptions)

smrt := smartypantsData{false, false} // first do normal entity escaping - escaped := bytes.NewBuffer(nil) - attrEscape(escaped, text) + var escaped bytes.Buffer + attrEscape(&escaped, text) text = escaped.Bytes() mark := 0