Skip to content

Commit

Permalink
fix unnecesssary allocation in infile.go (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
methane authored Jun 16, 2024
1 parent 87443b9 commit 2f69712
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions infile.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ const defaultPacketSize = 16 * 1024 // 16KB is small enough for disk readahead a

func (mc *okHandler) handleInFileRequest(name string) (err error) {
var rdr io.Reader
var data []byte
packetSize := defaultPacketSize
if mc.maxWriteSize < packetSize {
packetSize = mc.maxWriteSize
Expand Down Expand Up @@ -147,9 +146,11 @@ func (mc *okHandler) handleInFileRequest(name string) (err error) {
}

// send content packets
var data []byte

// if packetSize == 0, the Reader contains no data
if err == nil && packetSize > 0 {
data := make([]byte, 4+packetSize)
data = make([]byte, 4+packetSize)
var n int
for err == nil {
n, err = rdr.Read(data[4:])
Expand Down

0 comments on commit 2f69712

Please sign in to comment.