From 6c06c864258b6950919fc09fe1e35ab645d3c2f6 Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Thu, 20 Apr 2023 22:58:40 -0400 Subject: [PATCH] sqlite3: save an alloc during bind by using time.Time.AppendFormat This commit changes bind() to use time.Time.AppendFormat, which returns a byte slice, instead of time.Time.Format, which returns a string that must then be converted to a byte slice. This should save an allocation. --- sqlite3.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index ed2a9e2a..46885c26 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -1977,7 +1977,8 @@ func (s *SQLiteStmt) bind(args []driver.NamedValue) error { rv = C._sqlite3_bind_blob(s.s, n, unsafe.Pointer(&v[0]), C.int(ln)) } case time.Time: - b := []byte(v.Format(SQLiteTimestampFormats[0])) + b := make([]byte, 0, 35) // 35 == len(SQLiteTimestampFormats[0]) + b = v.AppendFormat(b, SQLiteTimestampFormats[0]) rv = C._sqlite3_bind_text(s.s, n, (*C.char)(unsafe.Pointer(&b[0])), C.int(len(b))) } if rv != C.SQLITE_OK {