소스 검색

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
 		}
 	}