Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(util/gconv): remove unnecessary logic for function doScanList #3588

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions util/gconv/gconv_scan_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package gconv

import (
"database/sql"
"reflect"

"github.com/gogf/gf/v2/errors/gcode"
Expand Down Expand Up @@ -115,9 +114,10 @@ func doScanList(
structSlice interface{}, structSlicePointer interface{}, bindToAttrName, relationAttrName, relationFields string,
) (err error) {
var (
maps = Maps(structSlice)
maps = Maps(structSlice)
lenMaps = len(maps)
)
if len(maps) == 0 {
if lenMaps == 0 {
return nil
}
// Necessary checks for parameters.
Expand Down Expand Up @@ -153,19 +153,6 @@ func doScanList(
reflectKind,
)
}
length := len(maps)
if length == 0 {
// The pointed slice is not empty.
if reflectValue.Len() > 0 {
// It here checks if it has struct item, which is already initialized.
// It then returns error to warn the developer its empty and no conversion.
if v := reflectValue.Index(0); v.Kind() != reflect.Ptr {
return sql.ErrNoRows
}
}
// Do nothing for empty struct slice.
return nil
}
var (
arrayValue reflect.Value // Like: []*Entity
arrayItemType reflect.Type // Like: *Entity
Expand All @@ -174,7 +161,7 @@ func doScanList(
if reflectValue.Len() > 0 {
arrayValue = reflectValue
} else {
arrayValue = reflect.MakeSlice(reflectType.Elem(), length, length)
arrayValue = reflect.MakeSlice(reflectType.Elem(), lenMaps, lenMaps)
}

// Slice element item.
Expand Down
Loading