generate: preallocate linewriter buffer
Current generated code is 200K, so 300K should be enough for a while.
@@ -24,7 +24,7 @@ func die(why string, args ...interface{}) {
type (
// LineWriter writes lines at a time.
LineWriter struct {
- buf bytes.Buffer
+ buf *bytes.Buffer
}
Type interface {
@@ -90,7 +90,7 @@ type (
)
func (l *LineWriter) Write(line string, args ...interface{}) {
- fmt.Fprintf(&l.buf, line, args...)
+ fmt.Fprintf(l.buf, line, args...)
l.buf.WriteByte('\n')
}
@@ -102,7 +102,7 @@ func main() {
}
Parse(f)
- l := new(LineWriter)
+ l := &LineWriter{bytes.NewBuffer(make([]byte, 0, 300<<10))}
l.Write("package kmsg")
l.Write(`import "github.com/twmb/kgo/kbin"`)
l.Write("// Code generated by kgo/generate. DO NOT EDIT.\n")
