Skip to content

Commit

Permalink
fix: reduce allocations when slice of values
Browse files Browse the repository at this point in the history
  • Loading branch information
Bexanderthebex committed May 30, 2022
1 parent 93986de commit 90cceca
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
switch reflectValue.Kind() {
case reflect.Slice, reflect.Array:
var elem reflect.Value
recyclableStruct := reflect.New(reflectValueType)

if !update || reflectValue.Len() == 0 {
update = false
Expand All @@ -261,7 +262,11 @@ func Scan(rows Rows, db *DB, mode ScanMode) {
}
}
} else {
elem = reflect.New(reflectValueType)
if isPtr {
elem = reflect.New(reflectValueType)
} else {
elem = recyclableStruct
}
}

db.scanIntoStruct(rows, elem, values, fields, joinFields)
Expand Down

0 comments on commit 90cceca

Please sign in to comment.