sqlite3: don't copy string in bind()

Change bind() to pass sqlite3_bind_text() a pointer to the strings data
instead of converting it to a []byte just so a pointer to `&b[0]` can be
passed to unsafe.Pointer. Basically, this saves a needless allocation.
and passing a pointer to that.

This is safe because sqlite3_bind_text does not keep a copy of the
provided string.
This commit is contained in:
Charlie Vieth 2023-04-20 23:14:11 -04:00
parent 3c0390b77c
commit 6bd4c94f64
No known key found for this signature in database
GPG Key ID: F6DBDE178E5DE3F0
1 changed files with 1 additions and 1 deletions

View File

@ -1953,7 +1953,7 @@ func (s *SQLiteStmt) bind(args []driver.NamedValue) error {
if len(v) == 0 {
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder[0])), C.int(0))
} else {
b := []byte(v)
b := *(*[]byte)(unsafe.Pointer(&v))
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
}
case int64: