]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: allocate once when assigning a time.Time to a byte slice
authorCharlie Vieth <charlie.vieth@gmail.com>
Sat, 26 Oct 2024 22:59:47 +0000 (18:59 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 29 Oct 2024 11:38:05 +0000 (11:38 +0000)
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 <carlos@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/database/sql/convert.go

index c261046b187e5271861d75cedb2ff872f76dc721..65fdfe6fa8c3ad2094d64741f303c71db5c160a1 100644 (file)
@@ -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 {