Skip to content

Commit 3fa7ed2

Browse files
committed
Use global variable for better performance.
1 parent 308f5f1 commit 3fa7ed2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

sqlite3.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ type bindArg struct {
734734
v driver.Value
735735
}
736736

737+
var placeHolder byte = 0
738+
737739
func (s *SQLiteStmt) bind(args []namedValue) error {
738740
rv := C.sqlite3_reset(s.s)
739741
if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE {
@@ -755,8 +757,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
755757
rv = C.sqlite3_bind_null(s.s, n)
756758
case string:
757759
if len(v) == 0 {
758-
b := []byte{0}
759-
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(0))
760+
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&placeHolder)), C.int(0))
760761
} else {
761762
b := []byte(v)
762763
rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b)))
@@ -774,7 +775,7 @@ func (s *SQLiteStmt) bind(args []namedValue) error {
774775
case []byte:
775776
var ptr *byte
776777
if len(v) == 0 {
777-
ptr = &(make([]byte, 1)[0])
778+
ptr = &placeHolder
778779
} else {
779780
ptr = &v[0]
780781
}

0 commit comments

Comments
 (0)