diff --git a/aclitem_array.go b/aclitem_array.go index 52b67d85..260bbe4c 100644 --- a/aclitem_array.go +++ b/aclitem_array.go @@ -29,6 +29,7 @@ func (dst *ACLItemArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -82,6 +83,9 @@ func (dst *ACLItemArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = ACLItemArray{Status: Null} @@ -187,6 +191,7 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -210,6 +215,9 @@ func (src *ACLItemArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -249,9 +257,8 @@ func (src *ACLItemArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/bool_array.go b/bool_array.go index 6a4b3454..149b0c9f 100644 --- a/bool_array.go +++ b/bool_array.go @@ -31,6 +31,7 @@ func (dst *BoolArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []bool: @@ -84,6 +85,9 @@ func (dst *BoolArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = BoolArray{Status: Null} @@ -189,6 +193,7 @@ func (src *BoolArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]bool: @@ -212,6 +217,9 @@ func (src *BoolArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *BoolArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/bpchar_array.go b/bpchar_array.go index 1f79a3fe..d28d22ac 100644 --- a/bpchar_array.go +++ b/bpchar_array.go @@ -31,6 +31,7 @@ func (dst *BPCharArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -84,6 +85,9 @@ func (dst *BPCharArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = BPCharArray{Status: Null} @@ -189,6 +193,7 @@ func (src *BPCharArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -212,6 +217,9 @@ func (src *BPCharArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *BPCharArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/bytea_array.go b/bytea_array.go index 17136554..26956edb 100644 --- a/bytea_array.go +++ b/bytea_array.go @@ -31,6 +31,7 @@ func (dst *ByteaArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case [][]byte: @@ -65,6 +66,9 @@ func (dst *ByteaArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = ByteaArray{Status: Null} @@ -170,6 +174,7 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[][]byte: @@ -184,6 +189,9 @@ func (src *ByteaArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -223,9 +231,8 @@ func (src *ByteaArray) assignToRecursive(value reflect.Value, index, dimension i length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/cidr_array.go b/cidr_array.go index 770c4b8c..d6108fe2 100644 --- a/cidr_array.go +++ b/cidr_array.go @@ -32,6 +32,7 @@ func (dst *CIDRArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []*net.IPNet: @@ -104,6 +105,9 @@ func (dst *CIDRArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = CIDRArray{Status: Null} @@ -209,6 +213,7 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]*net.IPNet: @@ -241,6 +246,9 @@ func (src *CIDRArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -280,9 +288,8 @@ func (src *CIDRArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/date_array.go b/date_array.go index 7ba93daa..e1b6061a 100644 --- a/date_array.go +++ b/date_array.go @@ -32,6 +32,7 @@ func (dst *DateArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []time.Time: @@ -85,6 +86,9 @@ func (dst *DateArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = DateArray{Status: Null} @@ -190,6 +194,7 @@ func (src *DateArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]time.Time: @@ -213,6 +218,9 @@ func (src *DateArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -252,9 +260,8 @@ func (src *DateArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/enum_array.go b/enum_array.go index 561d4495..b2fb063c 100644 --- a/enum_array.go +++ b/enum_array.go @@ -29,6 +29,7 @@ func (dst *EnumArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -82,6 +83,9 @@ func (dst *EnumArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = EnumArray{Status: Null} @@ -187,6 +191,7 @@ func (src *EnumArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -210,6 +215,9 @@ func (src *EnumArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -249,9 +257,8 @@ func (src *EnumArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/float4_array.go b/float4_array.go index 829708e1..7e750df8 100644 --- a/float4_array.go +++ b/float4_array.go @@ -31,6 +31,7 @@ func (dst *Float4Array) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []float32: @@ -84,6 +85,9 @@ func (dst *Float4Array) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = Float4Array{Status: Null} @@ -189,6 +193,7 @@ func (src *Float4Array) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]float32: @@ -212,6 +217,9 @@ func (src *Float4Array) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *Float4Array) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/float8_array.go b/float8_array.go index 6932cb88..12520722 100644 --- a/float8_array.go +++ b/float8_array.go @@ -31,6 +31,7 @@ func (dst *Float8Array) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []float64: @@ -84,6 +85,9 @@ func (dst *Float8Array) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = Float8Array{Status: Null} @@ -189,6 +193,7 @@ func (src *Float8Array) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]float64: @@ -212,6 +217,9 @@ func (src *Float8Array) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *Float8Array) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/hstore_array.go b/hstore_array.go index 4dc172be..d2ff2874 100644 --- a/hstore_array.go +++ b/hstore_array.go @@ -31,6 +31,7 @@ func (dst *HstoreArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []map[string]string: @@ -65,6 +66,9 @@ func (dst *HstoreArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = HstoreArray{Status: Null} @@ -170,6 +174,7 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]map[string]string: @@ -184,6 +189,9 @@ func (src *HstoreArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -223,9 +231,8 @@ func (src *HstoreArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/inet_array.go b/inet_array.go index 75f1328f..7133fc0b 100644 --- a/inet_array.go +++ b/inet_array.go @@ -32,6 +32,7 @@ func (dst *InetArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []*net.IPNet: @@ -104,6 +105,9 @@ func (dst *InetArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = InetArray{Status: Null} @@ -209,6 +213,7 @@ func (src *InetArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]*net.IPNet: @@ -241,6 +246,9 @@ func (src *InetArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -280,9 +288,8 @@ func (src *InetArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/int2_array.go b/int2_array.go index ede35bac..b64e0689 100644 --- a/int2_array.go +++ b/int2_array.go @@ -31,6 +31,7 @@ func (dst *Int2Array) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []int16: @@ -350,6 +351,9 @@ func (dst *Int2Array) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = Int2Array{Status: Null} @@ -455,6 +459,7 @@ func (src *Int2Array) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]int16: @@ -604,6 +609,9 @@ func (src *Int2Array) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -643,9 +651,8 @@ func (src *Int2Array) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/int4_array.go b/int4_array.go index b0856da9..01613d39 100644 --- a/int4_array.go +++ b/int4_array.go @@ -31,6 +31,7 @@ func (dst *Int4Array) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []int16: @@ -350,6 +351,9 @@ func (dst *Int4Array) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = Int4Array{Status: Null} @@ -455,6 +459,7 @@ func (src *Int4Array) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]int16: @@ -604,6 +609,9 @@ func (src *Int4Array) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -643,9 +651,8 @@ func (src *Int4Array) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/int8_array.go b/int8_array.go index c95ebef5..0babbe43 100644 --- a/int8_array.go +++ b/int8_array.go @@ -31,6 +31,7 @@ func (dst *Int8Array) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []int16: @@ -350,6 +351,9 @@ func (dst *Int8Array) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = Int8Array{Status: Null} @@ -455,6 +459,7 @@ func (src *Int8Array) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]int16: @@ -604,6 +609,9 @@ func (src *Int8Array) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -643,9 +651,8 @@ func (src *Int8Array) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/jsonb_array.go b/jsonb_array.go index faf2d364..1e82843d 100644 --- a/jsonb_array.go +++ b/jsonb_array.go @@ -31,6 +31,7 @@ func (dst *JSONBArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -65,6 +66,9 @@ func (dst *JSONBArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = JSONBArray{Status: Null} @@ -170,6 +174,7 @@ func (src *JSONBArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -184,6 +189,9 @@ func (src *JSONBArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -223,9 +231,8 @@ func (src *JSONBArray) assignToRecursive(value reflect.Value, index, dimension i length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/macaddr_array.go b/macaddr_array.go index 6f75ffbc..94a009fd 100644 --- a/macaddr_array.go +++ b/macaddr_array.go @@ -32,6 +32,7 @@ func (dst *MacaddrArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []net.HardwareAddr: @@ -85,6 +86,9 @@ func (dst *MacaddrArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = MacaddrArray{Status: Null} @@ -190,6 +194,7 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]net.HardwareAddr: @@ -213,6 +218,9 @@ func (src *MacaddrArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -252,9 +260,8 @@ func (src *MacaddrArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/numeric_array.go b/numeric_array.go index e848b133..884e8b14 100644 --- a/numeric_array.go +++ b/numeric_array.go @@ -31,6 +31,7 @@ func (dst *NumericArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []float32: @@ -198,6 +199,9 @@ func (dst *NumericArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = NumericArray{Status: Null} @@ -303,6 +307,7 @@ func (src *NumericArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]float32: @@ -380,6 +385,9 @@ func (src *NumericArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -419,9 +427,8 @@ func (src *NumericArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/text_array.go b/text_array.go index c6a950f8..b2825b29 100644 --- a/text_array.go +++ b/text_array.go @@ -31,6 +31,7 @@ func (dst *TextArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -84,6 +85,9 @@ func (dst *TextArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = TextArray{Status: Null} @@ -189,6 +193,7 @@ func (src *TextArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -212,6 +217,9 @@ func (src *TextArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *TextArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/timestamp_array.go b/timestamp_array.go index d0254d47..0bc30f17 100644 --- a/timestamp_array.go +++ b/timestamp_array.go @@ -32,6 +32,7 @@ func (dst *TimestampArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []time.Time: @@ -85,6 +86,9 @@ func (dst *TimestampArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = TimestampArray{Status: Null} @@ -190,6 +194,7 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]time.Time: @@ -213,6 +218,9 @@ func (src *TimestampArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -252,9 +260,8 @@ func (src *TimestampArray) assignToRecursive(value reflect.Value, index, dimensi length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/timestamptz_array.go b/timestamptz_array.go index 97ce2715..313bde81 100644 --- a/timestamptz_array.go +++ b/timestamptz_array.go @@ -32,6 +32,7 @@ func (dst *TimestamptzArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []time.Time: @@ -85,6 +86,9 @@ func (dst *TimestamptzArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = TimestamptzArray{Status: Null} @@ -190,6 +194,7 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]time.Time: @@ -213,6 +218,9 @@ func (src *TimestamptzArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -252,9 +260,8 @@ func (src *TimestamptzArray) assignToRecursive(value reflect.Value, index, dimen length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/tstzrange_array.go b/tstzrange_array.go index 02a98e66..216182df 100644 --- a/tstzrange_array.go +++ b/tstzrange_array.go @@ -31,6 +31,7 @@ func (dst *TstzrangeArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []Tstzrange: @@ -46,6 +47,9 @@ func (dst *TstzrangeArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = TstzrangeArray{Status: Null} @@ -151,6 +155,7 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]Tstzrange: @@ -165,6 +170,9 @@ func (src *TstzrangeArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -204,9 +212,8 @@ func (src *TstzrangeArray) assignToRecursive(value reflect.Value, index, dimensi length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/typed_array.go.erb b/typed_array.go.erb index 5bf582b2..809c7884 100644 --- a/typed_array.go.erb +++ b/typed_array.go.erb @@ -30,6 +30,7 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { <% go_array_types.split(",").each do |t| %> <% if t != "[]#{pgtype_element_type}" %> @@ -66,6 +67,9 @@ func (dst *<%= pgtype_array_type %>) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = <%= pgtype_array_type %>{Status: Null} @@ -171,6 +175,7 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1{ + // Attempt to match to select common types: switch v := dst.(type) { <% go_array_types.split(",").each do |t| %> case *<%= t %>: @@ -185,6 +190,9 @@ func (src *<%= pgtype_array_type %>) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -224,9 +232,8 @@ func (src *<%= pgtype_array_type %>) assignToRecursive(value reflect.Value, inde length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/uuid_array.go b/uuid_array.go index 09c6878f..47e348f3 100644 --- a/uuid_array.go +++ b/uuid_array.go @@ -31,6 +31,7 @@ func (dst *UUIDArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case [][16]byte: @@ -122,6 +123,9 @@ func (dst *UUIDArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = UUIDArray{Status: Null} @@ -227,6 +231,7 @@ func (src *UUIDArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[][16]byte: @@ -268,6 +273,9 @@ func (src *UUIDArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -307,9 +315,8 @@ func (src *UUIDArray) assignToRecursive(value reflect.Value, index, dimension in length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else { diff --git a/varchar_array.go b/varchar_array.go index ad19d423..e68614bb 100644 --- a/varchar_array.go +++ b/varchar_array.go @@ -31,6 +31,7 @@ func (dst *VarcharArray) Set(src interface{}) error { } } + // Attempt to match to select common types: switch value := src.(type) { case []string: @@ -84,6 +85,9 @@ func (dst *VarcharArray) Set(src interface{}) error { } } default: + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices reflectedValue := reflect.ValueOf(src) if !reflectedValue.IsValid() || reflectedValue.IsZero() { *dst = VarcharArray{Status: Null} @@ -189,6 +193,7 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { switch src.Status { case Present: if len(src.Dimensions) == 1 { + // Attempt to match to select common types: switch v := dst.(type) { case *[]string: @@ -212,6 +217,9 @@ func (src *VarcharArray) AssignTo(dst interface{}) error { } } + // Fallback to reflection if an optimised match was not found. + // The reflection is necessary for arrays and multidimensional slices, + // but it comes with a 20-50% performance penalty for large arrays/slices value := reflect.ValueOf(dst) if value.Kind() == reflect.Ptr { value = value.Elem() @@ -251,9 +259,8 @@ func (src *VarcharArray) assignToRecursive(value reflect.Value, index, dimension length := int(src.Dimensions[dimension].Length) if reflect.Array == kind { typ := value.Type() - typLen := typ.Len() - if typLen != length { - return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typLen) + if typ.Len() != length { + return 0, errors.Errorf("expected size %d array, but %s has size %d array", length, typ, typ.Len()) } value.Set(reflect.New(typ).Elem()) } else {