This change uses Go's memory model guarantees that the zero value memory shall be zeroed and hence to create a slice of 0 bytes aka padding, we can simply use make([]byte, N) which is much more efficient than bytes.Repeat([]byte{0}, N) and the benchmarks show this improvement:
$ benchstat before.txt after.txt
name old time/op new time/op delta
PaddingVsRepeat-8 674ns ± 1% 538ns ± 0% -20.22% (p=0.000 n=9+9)
name old alloc/op new alloc/op delta
PaddingVsRepeat-8 1.31kB ± 0% 0.83kB ± 0% -36.59% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
PaddingVsRepeat-8 12.0 ± 0% 11.0 ± 0% -8.33% (p=0.000 n=10+10)
This change uses Go's memory model guarantees that the zero value memory shall be zeroed and hence to create a slice of 0 bytes aka padding, we can simply use make([]byte, N) which is much more efficient than bytes.Repeat([]byte{0}, N) and the benchmarks show this improvement:
Fixes #41