فهرست منبع

query: Avoid binary.Write in GetRoutingKey

That last one introspects the type dynamically, which is around 100x
slower than using the PutUint16 function directly.
Adrien Bustany 10 سال پیش
والد
کامیت
fea9edbc92
1فایلهای تغییر یافته به همراه3 افزوده شده و 1 حذف شده
  1. 3 1
      session.go

+ 3 - 1
session.go

@@ -542,7 +542,9 @@ func (q *Query) GetRoutingKey() ([]byte, error) {
 		if err != nil {
 			return nil, err
 		}
-		binary.Write(buf, binary.BigEndian, int16(len(encoded)))
+		lenBuf := []byte{0x00, 0x00}
+		binary.BigEndian.PutUint16(lenBuf, uint16(len(encoded)))
+		buf.Write(lenBuf)
 		buf.Write(encoded)
 		buf.WriteByte(0x00)
 	}