mirror of https://github.com/jackc/pgx.git
Prevent every row scan from causing a malloc
parent
e3859aa03e
commit
6e2cee6294
7
query.go
7
query.go
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue