Skip to content

Commit

Permalink
sqlite3: save an alloc during bind by using time.Time.AppendFormat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
charlievieth committed Jul 23, 2024
1 parent 3c0390b commit 6c06c86
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6c06c86

Please sign in to comment.