Skip to content

Commit 9c80893

Browse files
committed
Uses explicit copy operations instead of append
Pre-allocate the data slice with the length of the remainingMsg (leftover from previous iteration) and the n bytes newly read into msgBuffer Copy the remainingMsg and the new n message bytes
1 parent a05c6a5 commit 9c80893

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

plugins/transport/socket/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ func (s *Socket) ReceiveData(maxBuffSize int64, done chan bool, pc net.Conn, w t
188188
// Combine remaining data from previous iteration with newly read data
189189
var data []byte
190190
if len(remainingMsg) > 0 {
191-
data = append(remainingMsg, msgBuffer[:n]...)
191+
data = make([]byte, len(remainingMsg)+n)
192+
copy(data, remainingMsg)
193+
copy(data[len(remainingMsg):], msgBuffer[:n])
192194
} else {
193195
data = msgBuffer[:n]
194196
}

0 commit comments

Comments
 (0)