Skip to content

Commit c5a59e8

Browse files
benchstat: accept io.Writer in FormatHTML, not *bytes.Buffer
This brings the API in-line with that of FormatText and FormatCSV and allows it to be used without necessitating an intermediate buffer. The change is fully backwards compatible and doesn't impose any potential performance cost because `html.Template.Execute` accepts an io.Writer, so any `bytes.Buffer` passed by reference to FormatHTML was already being forced to escape onto the heap. This might have been done this way to avoid questions about how the function should handle errors from Writer, but we already ignore those questions and panic in `FormatCSV`, so it seems reasonable that we would do the same thing here.
1 parent 36b577b commit c5a59e8

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

benchstat/html.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
package benchstat
66

77
import (
8-
"bytes"
98
"html/template"
9+
"io"
1010
"strings"
1111
)
1212

@@ -75,12 +75,7 @@ func htmlGroup(rows []*Row) (out [][]*Row) {
7575
return
7676
}
7777

78-
// FormatHTML appends an HTML formatting of the tables to buf.
79-
func FormatHTML(buf *bytes.Buffer, tables []*Table) {
80-
err := htmlTemplate.Execute(buf, tables)
81-
if err != nil {
82-
// Only possible errors here are template not matching data structure.
83-
// Don't make caller check - it's our fault.
84-
panic(err)
85-
}
78+
// FormatHTML appends an HTML formatting of the tables to w.
79+
func FormatHTML(w io.Writer, tables []*Table) {
80+
must(htmlTemplate.Execute(w, tables))
8681
}

0 commit comments

Comments
 (0)