From: Charlie Vieth Date: Sat, 26 Oct 2024 22:59:47 +0000 (-0400) Subject: database/sql: allocate once when assigning a time.Time to a byte slice X-Git-Tag: go1.24rc1~558 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ff86b8b62f1fc00920bb49023c91be3b24ea71bc;p=gostls13.git database/sql: allocate once when assigning a time.Time to a byte slice Change convertAssignRows to use time.AppendFormat and a pre-allocated buffer when assigning a time.Time to a byte slice. Previously, the result of time.Format was converted to a byte slice which required two allocations. Change-Id: I19db5e4d295e882070f947eca318a4e33520cda1 Reviewed-on: https://go-review.googlesource.com/c/go/+/622597 Reviewed-by: Carlos Amedee Auto-Submit: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI Reviewed-by: Ian Lance Taylor --- diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go index c261046b18..65fdfe6fa8 100644 --- a/src/database/sql/convert.go +++ b/src/database/sql/convert.go @@ -290,7 +290,7 @@ func convertAssignRows(dest, src any, rows *Rows) error { if d == nil { return errNilPtr } - *d = []byte(s.Format(time.RFC3339Nano)) + *d = s.AppendFormat(make([]byte, 0, len(time.RFC3339Nano)), time.RFC3339Nano) return nil case *RawBytes: if d == nil {