aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/convert.go
diff options
context:
space:
mode:
authorCyrill Schumacher <cyrill@schumacher.fm>2017-09-28 10:23:12 +0200
committerDaniel Theophanes <kardianos@gmail.com>2017-10-01 16:41:57 +0000
commit3487c4e02199b68d71df1868326e1b0a872a89a2 (patch)
treea73b9da715cd74845405357ffc93572a8a1df754 /src/database/sql/convert.go
parenta82ee9c76d979f8ea713caa13023dcfd747b433a (diff)
downloadgo-3487c4e02199b68d71df1868326e1b0a872a89a2.tar.xz
database/sql: convertAssign string and time.Time into RawBytes
A new switch case for converting the source string type into a destination RawBytes type avoids the reflection based conversion. Speed up from old ~61.7ns/op down to ~49ns/op. A second new switch case allows to convert and assign a source time.Time type into a destination sql.RawBytes type. This switch case appends the time to the reset RawBytes slice. This allows the reuse of RawBytes and avoids allocations. Fixes #20746 Change-Id: Ib0563fd5c5c7cb6d9d0acaa1d9aa7b2927f1329c Reviewed-on: https://go-review.googlesource.com/66830 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Theophanes <kardianos@gmail.com>
Diffstat (limited to 'src/database/sql/convert.go')
-rw-r--r--src/database/sql/convert.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/database/sql/convert.go b/src/database/sql/convert.go
index 3c387fb25c..c349a96edf 100644
--- a/src/database/sql/convert.go
+++ b/src/database/sql/convert.go
@@ -234,6 +234,12 @@ func convertAssign(dest, src interface{}) error {
}
*d = []byte(s)
return nil
+ case *RawBytes:
+ if d == nil {
+ return errNilPtr
+ }
+ *d = append((*d)[:0], s...)
+ return nil
}
case []byte:
switch d := dest.(type) {
@@ -273,6 +279,12 @@ func convertAssign(dest, src interface{}) error {
}
*d = []byte(s.Format(time.RFC3339Nano))
return nil
+ case *RawBytes:
+ if d == nil {
+ return errNilPtr
+ }
+ *d = s.AppendFormat((*d)[:0], time.RFC3339Nano)
+ return nil
}
case nil:
switch d := dest.(type) {