optimize value of reflection length (#4152)

This commit is contained in:
heige 2021-03-08 10:20:04 +08:00 committed by GitHub
parent a3abb5fedf
commit 221d0a0ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -35,10 +35,12 @@ func (db *DB) CreateInBatches(value interface{}, batchSize int) (tx *DB) {
tx = db.getInstance() tx = db.getInstance()
callFc := func(tx *DB) error { callFc := func(tx *DB) error {
for i := 0; i < reflectValue.Len(); i += batchSize { // the reflection length judgment of the optimized value
reflectLen := reflectValue.Len()
for i := 0; i < reflectLen; i += batchSize {
ends := i + batchSize ends := i + batchSize
if ends > reflectValue.Len() { if ends > reflectLen {
ends = reflectValue.Len() ends = reflectLen
} }
subtx := tx.getInstance() subtx := tx.getInstance()