Skip to content

Commit

Permalink
util/gconv: remove unnecessary logic for function doScanList (#3588)
Browse files Browse the repository at this point in the history
  • Loading branch information
oldme-git authored May 20, 2024
1 parent a9a0785 commit 737da95
Showing 1 changed file with 4 additions and 17 deletions.
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

0 comments on commit 737da95

Please sign in to comment.