diff --git a/schema/field.go b/schema/field.go index 77521ad3..fd8b2e6a 100644 --- a/schema/field.go +++ b/schema/field.go @@ -932,7 +932,6 @@ func (field *Field) setupValuerAndSetter() { } func (field *Field) setupNewValuePool() { - var fieldValue = reflect.New(field.FieldType).Interface() if field.Serializer != nil { field.NewValuePool = &sync.Pool{ New: func() interface{} { @@ -942,31 +941,9 @@ func (field *Field) setupNewValuePool() { } }, } - } else if _, ok := fieldValue.(sql.Scanner); !ok { - field.setupDefaultNewValuePool() } if field.NewValuePool == nil { field.NewValuePool = poolInitializer(reflect.PtrTo(field.IndirectFieldType)) } } - -func (field *Field) setupDefaultNewValuePool() { - // set default NewValuePool - switch field.IndirectFieldType.Kind() { - case reflect.String: - field.NewValuePool = stringPool - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - field.NewValuePool = intPool - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - field.NewValuePool = uintPool - case reflect.Float32, reflect.Float64: - field.NewValuePool = floatPool - case reflect.Bool: - field.NewValuePool = boolPool - default: - if field.IndirectFieldType == TimeReflectType { - field.NewValuePool = timePool - } - } -} diff --git a/schema/pool.go b/schema/pool.go index f5c73153..fa62fe22 100644 --- a/schema/pool.go +++ b/schema/pool.go @@ -3,54 +3,11 @@ package schema import ( "reflect" "sync" - "time" ) // sync pools var ( - normalPool sync.Map - stringPool = &sync.Pool{ - New: func() interface{} { - var v string - ptrV := &v - return &ptrV - }, - } - intPool = &sync.Pool{ - New: func() interface{} { - var v int64 - ptrV := &v - return &ptrV - }, - } - uintPool = &sync.Pool{ - New: func() interface{} { - var v uint64 - ptrV := &v - return &ptrV - }, - } - floatPool = &sync.Pool{ - New: func() interface{} { - var v float64 - ptrV := &v - return &ptrV - }, - } - boolPool = &sync.Pool{ - New: func() interface{} { - var v bool - ptrV := &v - return &ptrV - }, - } - timePool = &sync.Pool{ - New: func() interface{} { - var v time.Time - ptrV := &v - return &ptrV - }, - } + normalPool sync.Map poolInitializer = func(reflectType reflect.Type) FieldNewValuePool { v, _ := normalPool.LoadOrStore(reflectType, &sync.Pool{ New: func() interface{} { diff --git a/tests/go.mod b/tests/go.mod index fc6600b7..3ac4633e 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -5,15 +5,14 @@ go 1.14 require ( github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/google/uuid v1.3.0 - github.com/jackc/pgx/v4 v4.15.0 // indirect github.com/jinzhu/now v1.1.5 - github.com/lib/pq v1.10.4 + github.com/lib/pq v1.10.5 github.com/mattn/go-sqlite3 v1.14.12 // indirect - golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 // indirect - gorm.io/driver/mysql v1.3.2 - gorm.io/driver/postgres v1.3.1 + golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect + gorm.io/driver/mysql v1.3.3 + gorm.io/driver/postgres v1.3.4 gorm.io/driver/sqlite v1.3.1 - gorm.io/driver/sqlserver v1.3.1 + gorm.io/driver/sqlserver v1.3.2 gorm.io/gorm v1.23.3 )