Skip to content

Commit 7019692

Browse files
committed
reduce allocation for interpolateParams
1 parent 2e8bb88 commit 7019692

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

buffer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func (wb *writeBuffer) takeBuffer(length int) []byte {
3131
return make([]byte, length)
3232
}
3333

34+
func (wb *writeBuffer) store(buf []byte) {
35+
if cap(buf) < cap(wb.buf) || cap(buf) > maxPacketSize {
36+
return
37+
}
38+
wb.buf = buf
39+
}
40+
3441
type readBuffer struct {
3542
buf []byte
3643
idx int

connection.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ func (mc *mysqlConn) interpolateParams(query string, args []driver.Value) (strin
278278
if argPos != len(args) {
279279
return "", driver.ErrSkip
280280
}
281-
return string(buf), nil
281+
s := string(buf)
282+
mc.wbuf.store(buf[:0])
283+
return s, nil
282284
}
283285

284286
func (mc *mysqlConn) Exec(query string, args []driver.Value) (driver.Result, error) {

0 commit comments

Comments
 (0)