Skip to content

Commit

Permalink
refactor initialization of structures in internal/allocator/allocator.go
Browse files Browse the repository at this point in the history
  • Loading branch information
kozyrev-m committed Feb 9, 2024
1 parent d4987d9 commit 2f17a22
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Added explicit initialization of fields of structures in `internal/allocator/allocator.go`, when golangci-lint rendering is enabled
* Added explicit initialization of all fields of the `endpoint` structure in `internal/endpoint/endpoint.go`, when golangci-lint exhaustruct enabled

* Fixed topic writer infinite reconnections in some cases
Expand Down
48 changes: 26 additions & 22 deletions internal/allocator/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
"google.golang.org/protobuf/types/known/structpb"
)

type (
Expand Down Expand Up @@ -116,7 +117,7 @@ func (a *boolAllocator) Bool() (v *Ydb.Value_BoolValue) {

func (a *boolAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_BoolValue{}
*v = Ydb.Value_BoolValue{BoolValue: false}
boolPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -135,7 +136,7 @@ func (a *bytesAllocator) Bytes() (v *Ydb.Value_BytesValue) {

func (a *bytesAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_BytesValue{}
*v = Ydb.Value_BytesValue{BytesValue: []byte{}}
bytesPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -192,7 +193,7 @@ func (a *doubleAllocator) Double() (v *Ydb.Value_DoubleValue) {

func (a *doubleAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_DoubleValue{}
*v = Ydb.Value_DoubleValue{DoubleValue: 0}
doublePool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -211,7 +212,7 @@ func (a *floatAllocator) Float() (v *Ydb.Value_FloatValue) {

func (a *floatAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_FloatValue{}
*v = Ydb.Value_FloatValue{FloatValue: 0}
floatPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -230,7 +231,7 @@ func (a *int32Allocator) Int32() (v *Ydb.Value_Int32Value) {

func (a *int32Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Int32Value{}
*v = Ydb.Value_Int32Value{Int32Value: 0}
int32Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -249,7 +250,7 @@ func (a *int64Allocator) Int64() (v *Ydb.Value_Int64Value) {

func (a *int64Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Int64Value{}
*v = Ydb.Value_Int64Value{Int64Value: 0}
int64Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -287,7 +288,7 @@ func (a *low128Allocator) Low128() (v *Ydb.Value_Low_128) {

func (a *low128Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Low_128{}
*v = Ydb.Value_Low_128{Low_128: 0}
low128Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -306,7 +307,7 @@ func (a *nestedAllocator) Nested() (v *Ydb.Value_NestedValue) {

func (a *nestedAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_NestedValue{}
*v = Ydb.Value_NestedValue{NestedValue: new(Ydb.Value)}
nestedPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -325,7 +326,7 @@ func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) {

func (a *nullFlagAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_NullFlagValue{}
*v = Ydb.Value_NullFlagValue{NullFlagValue: structpb.NullValue_NULL_VALUE}
nullFlagPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -363,7 +364,10 @@ func (a *pairAllocator) Pair() (v *Ydb.ValuePair) {

func (a *pairAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.ValuePair{}
*v = Ydb.ValuePair{
Key: new(Ydb.Value),
Payload: new(Ydb.Value),
}
pairPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -428,7 +432,7 @@ func (a *textAllocator) Text() (v *Ydb.Value_TextValue) {

func (a *textAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_TextValue{}
*v = Ydb.Value_TextValue{TextValue: ""}
textPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -471,7 +475,7 @@ func (a *typeDecimalAllocator) TypeDecimal() (v *Ydb.Type_DecimalType) {

func (a *typeDecimalAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_DecimalType{}
*v = Ydb.Type_DecimalType{DecimalType: new(Ydb.DecimalType)}
typeDecimalPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -490,7 +494,7 @@ func (a *typeDictAllocator) TypeDict() (v *Ydb.Type_DictType) {

func (a *typeDictAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_DictType{}
*v = Ydb.Type_DictType{DictType: new(Ydb.DictType)}
typeDictPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -509,7 +513,7 @@ func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) {

func (a *typeEmptyListAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_EmptyListType{}
*v = Ydb.Type_EmptyListType{EmptyListType: structpb.NullValue_NULL_VALUE}
typeEmptyListPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -528,7 +532,7 @@ func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) {

func (a *typeEmptyDictAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_EmptyDictType{}
*v = Ydb.Type_EmptyDictType{EmptyDictType: structpb.NullValue_NULL_VALUE}
typeEmptyDictPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -566,7 +570,7 @@ func (a *typeListAllocator) TypeList() (v *Ydb.Type_ListType) {

func (a *typeListAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_ListType{}
*v = Ydb.Type_ListType{ListType: new(Ydb.ListType)}
typeListPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -585,7 +589,7 @@ func (a *typeOptionalAllocator) TypeOptional() (v *Ydb.Type_OptionalType) {

func (a *typeOptionalAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_OptionalType{}
*v = Ydb.Type_OptionalType{OptionalType: new(Ydb.OptionalType)}
typeOptionalPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -604,7 +608,7 @@ func (a *typeStructAllocator) TypeStruct() (v *Ydb.Type_StructType) {

func (a *typeStructAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_StructType{}
*v = Ydb.Type_StructType{StructType: new(Ydb.StructType)}
typeStructPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -623,7 +627,7 @@ func (a *typeTupleAllocator) TypeTuple() (v *Ydb.Type_TupleType) {

func (a *typeTupleAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_TupleType{}
*v = Ydb.Type_TupleType{TupleType: new(Ydb.TupleType)}
typeTuplePool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -642,7 +646,7 @@ func (a *typeVariantAllocator) TypeVariant() (v *Ydb.Type_VariantType) {

func (a *typeVariantAllocator) free() {
for _, v := range a.allocations {
*v = Ydb.Type_VariantType{}
*v = Ydb.Type_VariantType{VariantType: new(Ydb.VariantType)}
typeVariantPool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down Expand Up @@ -680,7 +684,7 @@ func (a *uint32Allocator) Uint32() (v *Ydb.Value_Uint32Value) {

func (a *uint32Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Uint32Value{}
*v = Ydb.Value_Uint32Value{Uint32Value: 0}
uint32Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand All @@ -699,7 +703,7 @@ func (a *uint64Allocator) Uint64() (v *Ydb.Value_Uint64Value) {

func (a *uint64Allocator) free() {
for _, v := range a.allocations {
*v = Ydb.Value_Uint64Value{}
*v = Ydb.Value_Uint64Value{Uint64Value: 0}
uint64Pool.Put(v)
}
a.allocations = a.allocations[:0]
Expand Down

0 comments on commit 2f17a22

Please sign in to comment.