Skip to content

Commit

Permalink
sqlite3: don't copy string in bind()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
charlievieth committed Jul 23, 2024
1 parent 3c0390b commit 6bd4c94
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6bd4c94

Please sign in to comment.