Skip to content

Commit aaa266b

Browse files
committed
Don't create a variable for len of data binding []byte
The len of d is in runtime cache, create a variable for each lean causes a light overhead.
1 parent 75cd6ac commit aaa266b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

param.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,16 @@ func (p *Parameter) BindValue(h api.SQLHSTMT, idx int, v driver.Value) error {
119119
}
120120
size = 20 + api.SQLULEN(decimal)
121121
case []byte:
122-
lenD := len(d)
123122
ctype = api.SQL_C_BINARY
124-
b := make([]byte, lenD)
123+
b := make([]byte, len(d))
125124
copy(b, d)
126125
p.Data = b
127-
if lenD > 0 {
126+
if len(d) > 0 {
128127
buf = unsafe.Pointer(&b[0])
129128
}
130-
buflen = api.SQLLEN(lenD)
129+
buflen = api.SQLLEN(len(b))
131130
plen = p.StoreStrLen_or_IndPtr(buflen)
132-
size = api.SQLULEN(lenD)
131+
size = api.SQLULEN(len(b))
133132
sqltype = api.SQL_BINARY
134133
case sql.Out:
135134
o, err := newOut(h, &d, idx)

0 commit comments

Comments
 (0)