Commit 15ac56fd authored by Author Name's avatar Author Name Committed by Brad Fitzpatrick

io: calculate buffer size only when needed

Change-Id: I930be9027fb972198b3d44816a5e4f53ff7eb5ea
Reviewed-on: https://go-review.googlesource.com/111642Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c9c73978
...@@ -387,6 +387,7 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) { ...@@ -387,6 +387,7 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) {
if rt, ok := dst.(ReaderFrom); ok { if rt, ok := dst.(ReaderFrom); ok {
return rt.ReadFrom(src) return rt.ReadFrom(src)
} }
if buf == nil {
size := 32 * 1024 size := 32 * 1024
if l, ok := src.(*LimitedReader); ok && int64(size) > l.N { if l, ok := src.(*LimitedReader); ok && int64(size) > l.N {
if l.N < 1 { if l.N < 1 {
...@@ -395,7 +396,6 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) { ...@@ -395,7 +396,6 @@ func copyBuffer(dst Writer, src Reader, buf []byte) (written int64, err error) {
size = int(l.N) size = int(l.N)
} }
} }
if buf == nil {
buf = make([]byte, size) buf = make([]byte, size)
} }
for { for {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment