Skip to content

Commit

Permalink
support scan assign slice cap (#5634)
Browse files Browse the repository at this point in the history
* support scan assign slice cap

* fix
  • Loading branch information
demoManito authored and jinzhu committed Sep 22, 2022
1 parent c41ecf6 commit 35402e1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scan.go
Expand Up @@ -248,7 +248,13 @@ 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))
// if the slice cap is externally initialized, the externally initialized slice is directly used here
if reflectValue.Cap() == 0 {
db.Statement.ReflectValue.Set(reflect.MakeSlice(reflectValue.Type(), 0, 20))
} else {
reflectValue.SetLen(0)
db.Statement.ReflectValue.Set(reflectValue)
}
}

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

0 comments on commit 35402e1

Please sign in to comment.