Skip to content

Commit 316bbe0

Browse files
committed
cgosqlite: remove allocs in bind_{int64,null,double}
Updates tailscale/corp#9919 Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent 8a7a943 commit 316bbe0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cgosqlite/cgosqlite.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,15 @@ func (stmt *Stmt) StepResult() (row bool, lastInsertRowID, changes int64, d time
302302
}
303303

304304
func (stmt *Stmt) BindDouble(col int, val float64) error {
305-
return errCode(C.sqlite3_bind_double(stmt.stmt.ptr(), C.int(col), C.double(val)))
305+
return errCode(C.ts_sqlite3_bind_double(stmt.stmt.int(), C.int(col), C.double(val)))
306306
}
307307

308308
func (stmt *Stmt) BindInt64(col int, val int64) error {
309-
return errCode(C.sqlite3_bind_int64(stmt.stmt.ptr(), C.int(col), C.sqlite3_int64(val)))
309+
return errCode(C.ts_sqlite3_bind_int64(stmt.stmt.int(), C.int(col), C.sqlite3_int64(val)))
310310
}
311311

312312
func (stmt *Stmt) BindNull(col int) error {
313-
return errCode(C.sqlite3_bind_null(stmt.stmt.ptr(), C.int(col)))
313+
return errCode(C.ts_sqlite3_bind_null(stmt.stmt.int(), C.int(col)))
314314
}
315315

316316
func (stmt *Stmt) BindText64(col int, val string) error {

cgosqlite/cgosqlite.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ static int bind_blob64(handle_sqlite3_stmt stmt, int col, char* str, sqlite3_uin
2323
return sqlite3_bind_blob64((sqlite3_stmt*)(stmt), col, str, n, SQLITE_TRANSIENT);
2424
}
2525

26+
static int ts_sqlite3_bind_double(handle_sqlite3_stmt stmt, int col, double v) {
27+
return sqlite3_bind_double((sqlite3_stmt*)(stmt), col, v);
28+
}
29+
30+
static int ts_sqlite3_bind_int64(handle_sqlite3_stmt stmt, int col, sqlite3_int64 v) {
31+
return sqlite3_bind_int64((sqlite3_stmt*)(stmt), col, v);
32+
}
33+
34+
static int ts_sqlite3_bind_null(handle_sqlite3_stmt stmt, int col) {
35+
return sqlite3_bind_null((sqlite3_stmt*)(stmt), col);
36+
}
37+
2638
// We only need the Go string's memory for the duration of the call,
2739
// and the GC pins it for us if we pass the gostring_t to C, so we
2840
// do the conversion here instead of with C.CString.

0 commit comments

Comments
 (0)