We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a602069 commit 7ac8bc9Copy full SHA for 7ac8bc9
buffer.go
@@ -55,20 +55,22 @@ func (b *buffer) fill(need int) (err error) {
55
return
56
}
57
58
+// grow the buffer to the given size
59
// credit for this code snippet goes to Maxim Khitrov
60
// https://groups.google.com/forum/#!topic/golang-nuts/ETbw1ECDgRs
61
func (b *buffer) grow(size int) {
62
+ // If append would be too expensive, alloc a new slice
63
if size > 2*cap(b.buf) {
64
newBuf := make([]byte, size)
65
copy(newBuf, b.buf)
66
b.buf = newBuf
67
- } else {
- 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
+
+ for cap(b.buf) < size {
+ b.buf = append(b.buf[:cap(b.buf)], 0)
72
+ }
73
+ b.buf = b.buf[:cap(b.buf)]
74
75
76
// returns next N bytes from buffer.
0 commit comments