Skip to content

Commit 7847296

Browse files
committed
Avoid buffer copying for non-splitting packets
1 parent 745998a commit 7847296

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packets.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,16 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
6161
return nil, driver.ErrBadConn
6262
}
6363

64+
isLastPacket := (pktLen < maxPacketSize)
65+
66+
// Zero allocations for non-splitting packets
67+
if isLastPacket && payload == nil {
68+
return data, nil
69+
}
70+
6471
payload = append(payload, data...)
6572

66-
if pktLen < maxPacketSize {
73+
if isLastPacket {
6774
return payload, nil
6875
}
6976
}

0 commit comments

Comments
 (0)