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) {
55
55
return
56
56
}
57
57
58
+ // grow the buffer to the given size
58
59
// credit for this code snippet goes to Maxim Khitrov
59
60
// https://groups.google.com/forum/#!topic/golang-nuts/ETbw1ECDgRs
60
61
func (b * buffer ) grow (size int ) {
62
+ // If append would be too expensive, alloc a new slice
61
63
if size > 2 * cap (b .buf ) {
62
64
newBuf := make ([]byte , size )
63
65
copy (newBuf , b .buf )
64
66
b .buf = newBuf
65
67
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 )]
71
68
}
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 )]
72
74
}
73
75
74
76
// returns next N bytes from buffer.
You can’t perform that action at this time.
0 commit comments