瀏覽代碼

Avoid buffer copying for non-splitting packets

Xiuming Chen 12 年之前
父節點
當前提交
7847296546
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      packets.go

+ 8 - 1
packets.go

@@ -61,9 +61,16 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
 			return nil, driver.ErrBadConn
 		}
 
+		isLastPacket := (pktLen < maxPacketSize)
+
+		// Zero allocations for non-splitting packets
+		if isLastPacket && payload == nil {
+			return data, nil
+		}
+
 		payload = append(payload, data...)
 
-		if pktLen < maxPacketSize {
+		if isLastPacket {
 			return payload, nil
 		}
 	}