File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -55,20 +55,22 @@ func (b *buffer) fill(need int) (err error) {
5555 return
5656}
5757
58+ // grow the buffer to the given size
5859// credit for this code snippet goes to Maxim Khitrov
5960// https://groups.google.com/forum/#!topic/golang-nuts/ETbw1ECDgRs
6061func (b * buffer ) grow (size int ) {
62+ // If append would be too expensive, alloc a new slice
6163 if size > 2 * cap (b .buf ) {
6264 newBuf := make ([]byte , size )
6365 copy (newBuf , b .buf )
6466 b .buf = newBuf
6567 return
66- } else {
67- for cap (b .buf ) < size {
68- b .buf = append (b .buf [:cap (b .buf )], 0 )
69- }
70- b .buf = b .buf [:cap (b .buf )]
7168 }
69+
70+ for cap (b .buf ) < size {
71+ b .buf = append (b .buf [:cap (b .buf )], 0 )
72+ }
73+ b .buf = b .buf [:cap (b .buf )]
7274}
7375
7476// returns next N bytes from buffer.
You can’t perform that action at this time.
0 commit comments