From 221d0a0ec1c929182cab16e9c2620dfae459796a Mon Sep 17 00:00:00 2001 From: heige Date: Mon, 8 Mar 2021 10:20:04 +0800 Subject: [PATCH] optimize value of reflection length (#4152) --- finisher_api.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/finisher_api.go b/finisher_api.go index 2d7409c7..bef65ae5 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -35,10 +35,12 @@ func (db *DB) CreateInBatches(value interface{}, batchSize int) (tx *DB) { tx = db.getInstance() 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 - if ends > reflectValue.Len() { - ends = reflectValue.Len() + if ends > reflectLen { + ends = reflectLen } subtx := tx.getInstance()