Skip to content

Commit

Permalink
support scan assign slice cap
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Aug 24, 2022
1 parent 8c3018b commit 0e655ba
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scan.go
Expand Up @@ -246,7 +246,11 @@ func Scan(rows Rows, db *DB, mode ScanMode) {

if !update || reflectValue.Len() == 0 {
update = false
db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20))
sliceCap := reflectValue.Cap()
if sliceCap <= 0 {
sliceCap = 20
}
db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, sliceCap))
}

for initialized || rows.Next() {
Expand Down

0 comments on commit 0e655ba

Please sign in to comment.