Prevent every row scan from causing a malloc

alloc-reduction
Jack Christensen 2016-04-30 12:54:16 -05:00
parent e3859aa03e
commit 6e2cee6294
1 changed files with 6 additions and 1 deletions

View File

@ -301,7 +301,12 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
rows.Fatal(scanArgError{col: i, err: err})
}
} else if vr.Type().DataType == JsonOid || vr.Type().DataType == JsonbOid {
decodeJSON(vr, &d)
// Because the argument passed to decodeJSON will escape the heap.
// This allows d to be stack allocated and only copied to the heap when
// we actually are decoding JSON. This saves one memory allocation per
// row.
d2 := d
decodeJSON(vr, &d2)
} else {
if err := Decode(vr, d); err != nil {
rows.Fatal(scanArgError{col: i, err: err})