optimize value of reflection length

This commit is contained in:
daheige 2021-03-07 11:05:40 +08:00
parent a948c84607
commit 240290f14d

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()