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 Sep 5, 2022
1 parent b3eb1c8 commit 0a96898
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scan.go
Expand Up @@ -248,7 +248,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 0a96898

Please sign in to comment.