github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/allocator/allocator.go (about)

     1  package allocator
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
     7  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"
     8  	"github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Table"
     9  )
    10  
    11  type (
    12  	Allocator struct {
    13  		valueAllocator
    14  		typeAllocator
    15  		typedValueAllocator
    16  		boolAllocator
    17  		typeDecimalAllocator
    18  		typeListAllocator
    19  		typeEmptyListAllocator
    20  		typeEmptyDictAllocator
    21  		typeTupleAllocator
    22  		typeStructAllocator
    23  		typeDictAllocator
    24  		decimalAllocator
    25  		listAllocator
    26  		tupleAllocator
    27  		structAllocator
    28  		dictAllocator
    29  		structMemberAllocator
    30  		typeOptionalAllocator
    31  		optionalAllocator
    32  		bytesAllocator
    33  		textAllocator
    34  		uint32Allocator
    35  		int32Allocator
    36  		low128Allocator
    37  		uint64Allocator
    38  		int64Allocator
    39  		floatAllocator
    40  		doubleAllocator
    41  		nestedAllocator
    42  		pairAllocator
    43  		nullFlagAllocator
    44  		variantAllocator
    45  		typeVariantAllocator
    46  		variantStructItemsAllocator
    47  		variantTupleItemsAllocator
    48  		tableExecuteQueryResultAllocator
    49  		tableExecuteQueryRequestAllocator
    50  		tableQueryCachePolicyAllocator
    51  		tableQueryAllocator
    52  		tableQueryYqlTextAllocator
    53  		tableQueryIDAllocator
    54  		queryExecuteQueryRequestAllocator
    55  		queryExecuteQueryRequestQueryContentAllocator
    56  		queryExecuteQueryResponsePartAllocator
    57  		queryQueryContentAllocator
    58  		queryTransactionControlAllocator
    59  		queryTransactionControlBeginTxAllocator
    60  		queryTransactionControlTxIDAllocator
    61  		queryTransactionSettingsAllocator
    62  		queryTransactionSettingsSerializableReadWriteAllocator
    63  	}
    64  )
    65  
    66  func New() (v *Allocator) {
    67  	return allocatorPool.Get()
    68  }
    69  
    70  func (a *Allocator) Free() {
    71  	a.valueAllocator.free()
    72  	a.typeAllocator.free()
    73  	a.typedValueAllocator.free()
    74  	a.boolAllocator.free()
    75  	a.typeDecimalAllocator.free()
    76  	a.typeListAllocator.free()
    77  	a.typeEmptyListAllocator.free()
    78  	a.typeEmptyDictAllocator.free()
    79  	a.typeTupleAllocator.free()
    80  	a.typeStructAllocator.free()
    81  	a.typeDictAllocator.free()
    82  	a.decimalAllocator.free()
    83  	a.listAllocator.free()
    84  	a.tupleAllocator.free()
    85  	a.structAllocator.free()
    86  	a.dictAllocator.free()
    87  	a.structMemberAllocator.free()
    88  	a.typeOptionalAllocator.free()
    89  	a.optionalAllocator.free()
    90  	a.bytesAllocator.free()
    91  	a.textAllocator.free()
    92  	a.uint32Allocator.free()
    93  	a.int32Allocator.free()
    94  	a.low128Allocator.free()
    95  	a.uint64Allocator.free()
    96  	a.int64Allocator.free()
    97  	a.floatAllocator.free()
    98  	a.doubleAllocator.free()
    99  	a.nestedAllocator.free()
   100  	a.pairAllocator.free()
   101  	a.nullFlagAllocator.free()
   102  	a.variantAllocator.free()
   103  	a.typeVariantAllocator.free()
   104  	a.variantStructItemsAllocator.free()
   105  	a.variantTupleItemsAllocator.free()
   106  	a.tableExecuteQueryRequestAllocator.free()
   107  	a.tableExecuteQueryResultAllocator.free()
   108  	a.tableQueryCachePolicyAllocator.free()
   109  	a.tableQueryAllocator.free()
   110  	a.tableQueryYqlTextAllocator.free()
   111  	a.tableQueryIDAllocator.free()
   112  	a.queryExecuteQueryRequestAllocator.free()
   113  	a.queryExecuteQueryRequestQueryContentAllocator.free()
   114  	a.queryExecuteQueryResponsePartAllocator.free()
   115  	a.queryQueryContentAllocator.free()
   116  	a.queryTransactionControlAllocator.free()
   117  	a.queryTransactionControlBeginTxAllocator.free()
   118  	a.queryTransactionControlTxIDAllocator.free()
   119  	a.queryTransactionSettingsAllocator.free()
   120  	a.queryTransactionSettingsSerializableReadWriteAllocator.free()
   121  
   122  	allocatorPool.Put(a)
   123  }
   124  
   125  type boolAllocator struct {
   126  	allocations []*Ydb.Value_BoolValue
   127  }
   128  
   129  func (a *boolAllocator) Bool() (v *Ydb.Value_BoolValue) {
   130  	v = boolPool.Get()
   131  	a.allocations = append(a.allocations, v)
   132  
   133  	return v
   134  }
   135  
   136  func (a *boolAllocator) free() {
   137  	for _, v := range a.allocations {
   138  		*v = Ydb.Value_BoolValue{}
   139  		boolPool.Put(v)
   140  	}
   141  	a.allocations = a.allocations[:0]
   142  }
   143  
   144  type bytesAllocator struct {
   145  	allocations []*Ydb.Value_BytesValue
   146  }
   147  
   148  func (a *bytesAllocator) Bytes() (v *Ydb.Value_BytesValue) {
   149  	v = bytesPool.Get()
   150  	a.allocations = append(a.allocations, v)
   151  
   152  	return v
   153  }
   154  
   155  func (a *bytesAllocator) free() {
   156  	for _, v := range a.allocations {
   157  		*v = Ydb.Value_BytesValue{}
   158  		bytesPool.Put(v)
   159  	}
   160  	a.allocations = a.allocations[:0]
   161  }
   162  
   163  type decimalAllocator struct {
   164  	allocations []*Ydb.DecimalType
   165  }
   166  
   167  func (a *decimalAllocator) Decimal() (v *Ydb.DecimalType) {
   168  	v = decimalPool.Get()
   169  	a.allocations = append(a.allocations, v)
   170  
   171  	return v
   172  }
   173  
   174  func (a *decimalAllocator) free() {
   175  	for _, v := range a.allocations {
   176  		v.Reset()
   177  		decimalPool.Put(v)
   178  	}
   179  	a.allocations = a.allocations[:0]
   180  }
   181  
   182  type dictAllocator struct {
   183  	allocations []*Ydb.DictType
   184  }
   185  
   186  func (a *dictAllocator) Dict() (v *Ydb.DictType) {
   187  	v = dictPool.Get()
   188  	a.allocations = append(a.allocations, v)
   189  
   190  	return v
   191  }
   192  
   193  func (a *dictAllocator) free() {
   194  	for _, v := range a.allocations {
   195  		v.Reset()
   196  		dictPool.Put(v)
   197  	}
   198  	a.allocations = a.allocations[:0]
   199  }
   200  
   201  type doubleAllocator struct {
   202  	allocations []*Ydb.Value_DoubleValue
   203  }
   204  
   205  func (a *doubleAllocator) Double() (v *Ydb.Value_DoubleValue) {
   206  	v = doublePool.Get()
   207  	a.allocations = append(a.allocations, v)
   208  
   209  	return v
   210  }
   211  
   212  func (a *doubleAllocator) free() {
   213  	for _, v := range a.allocations {
   214  		*v = Ydb.Value_DoubleValue{}
   215  		doublePool.Put(v)
   216  	}
   217  	a.allocations = a.allocations[:0]
   218  }
   219  
   220  type floatAllocator struct {
   221  	allocations []*Ydb.Value_FloatValue
   222  }
   223  
   224  func (a *floatAllocator) Float() (v *Ydb.Value_FloatValue) {
   225  	v = floatPool.Get()
   226  	a.allocations = append(a.allocations, v)
   227  
   228  	return v
   229  }
   230  
   231  func (a *floatAllocator) free() {
   232  	for _, v := range a.allocations {
   233  		*v = Ydb.Value_FloatValue{}
   234  		floatPool.Put(v)
   235  	}
   236  	a.allocations = a.allocations[:0]
   237  }
   238  
   239  type int32Allocator struct {
   240  	allocations []*Ydb.Value_Int32Value
   241  }
   242  
   243  func (a *int32Allocator) Int32() (v *Ydb.Value_Int32Value) {
   244  	v = int32Pool.Get()
   245  	a.allocations = append(a.allocations, v)
   246  
   247  	return v
   248  }
   249  
   250  func (a *int32Allocator) free() {
   251  	for _, v := range a.allocations {
   252  		*v = Ydb.Value_Int32Value{}
   253  		int32Pool.Put(v)
   254  	}
   255  	a.allocations = a.allocations[:0]
   256  }
   257  
   258  type int64Allocator struct {
   259  	allocations []*Ydb.Value_Int64Value
   260  }
   261  
   262  func (a *int64Allocator) Int64() (v *Ydb.Value_Int64Value) {
   263  	v = int64Pool.Get()
   264  	a.allocations = append(a.allocations, v)
   265  
   266  	return v
   267  }
   268  
   269  func (a *int64Allocator) free() {
   270  	for _, v := range a.allocations {
   271  		*v = Ydb.Value_Int64Value{}
   272  		int64Pool.Put(v)
   273  	}
   274  	a.allocations = a.allocations[:0]
   275  }
   276  
   277  type listAllocator struct {
   278  	allocations []*Ydb.ListType
   279  }
   280  
   281  func (a *listAllocator) List() (v *Ydb.ListType) {
   282  	v = listPool.Get()
   283  	a.allocations = append(a.allocations, v)
   284  
   285  	return v
   286  }
   287  
   288  func (a *listAllocator) free() {
   289  	for _, v := range a.allocations {
   290  		v.Reset()
   291  		listPool.Put(v)
   292  	}
   293  	a.allocations = a.allocations[:0]
   294  }
   295  
   296  type low128Allocator struct {
   297  	allocations []*Ydb.Value_Low_128
   298  }
   299  
   300  func (a *low128Allocator) Low128() (v *Ydb.Value_Low_128) {
   301  	v = low128Pool.Get()
   302  	a.allocations = append(a.allocations, v)
   303  
   304  	return v
   305  }
   306  
   307  func (a *low128Allocator) free() {
   308  	for _, v := range a.allocations {
   309  		*v = Ydb.Value_Low_128{}
   310  		low128Pool.Put(v)
   311  	}
   312  	a.allocations = a.allocations[:0]
   313  }
   314  
   315  type nestedAllocator struct {
   316  	allocations []*Ydb.Value_NestedValue
   317  }
   318  
   319  func (a *nestedAllocator) Nested() (v *Ydb.Value_NestedValue) {
   320  	v = nestedPool.Get()
   321  	a.allocations = append(a.allocations, v)
   322  
   323  	return v
   324  }
   325  
   326  func (a *nestedAllocator) free() {
   327  	for _, v := range a.allocations {
   328  		*v = Ydb.Value_NestedValue{}
   329  		nestedPool.Put(v)
   330  	}
   331  	a.allocations = a.allocations[:0]
   332  }
   333  
   334  type nullFlagAllocator struct {
   335  	allocations []*Ydb.Value_NullFlagValue
   336  }
   337  
   338  func (a *nullFlagAllocator) NullFlag() (v *Ydb.Value_NullFlagValue) {
   339  	v = nullFlagPool.Get()
   340  	a.allocations = append(a.allocations, v)
   341  
   342  	return v
   343  }
   344  
   345  func (a *nullFlagAllocator) free() {
   346  	for _, v := range a.allocations {
   347  		*v = Ydb.Value_NullFlagValue{}
   348  		nullFlagPool.Put(v)
   349  	}
   350  	a.allocations = a.allocations[:0]
   351  }
   352  
   353  type optionalAllocator struct {
   354  	allocations []*Ydb.OptionalType
   355  }
   356  
   357  func (a *optionalAllocator) Optional() (v *Ydb.OptionalType) {
   358  	v = optionalPool.Get()
   359  	a.allocations = append(a.allocations, v)
   360  
   361  	return v
   362  }
   363  
   364  func (a *optionalAllocator) free() {
   365  	for _, v := range a.allocations {
   366  		v.Reset()
   367  		optionalPool.Put(v)
   368  	}
   369  	a.allocations = a.allocations[:0]
   370  }
   371  
   372  type pairAllocator struct {
   373  	allocations []*Ydb.ValuePair
   374  }
   375  
   376  func (a *pairAllocator) Pair() (v *Ydb.ValuePair) {
   377  	v = pairPool.Get()
   378  	a.allocations = append(a.allocations, v)
   379  
   380  	return v
   381  }
   382  
   383  func (a *pairAllocator) free() {
   384  	for _, v := range a.allocations {
   385  		*v = Ydb.ValuePair{}
   386  		pairPool.Put(v)
   387  	}
   388  	a.allocations = a.allocations[:0]
   389  }
   390  
   391  type structAllocator struct {
   392  	allocations []*Ydb.StructType
   393  }
   394  
   395  func (a *structAllocator) Struct() (v *Ydb.StructType) {
   396  	v = structPool.Get()
   397  	if cap(v.GetMembers()) <= 0 {
   398  		v.Members = make([]*Ydb.StructMember, 0, 10)
   399  	}
   400  	a.allocations = append(a.allocations, v)
   401  
   402  	return v
   403  }
   404  
   405  func (a *structAllocator) free() {
   406  	for _, v := range a.allocations {
   407  		members := v.GetMembers()
   408  		for i := range members {
   409  			members[i] = nil
   410  		}
   411  		v.Reset()
   412  		v.Members = members[:0]
   413  		structPool.Put(v)
   414  	}
   415  	a.allocations = a.allocations[:0]
   416  }
   417  
   418  type structMemberAllocator struct {
   419  	allocations []*Ydb.StructMember
   420  }
   421  
   422  func (a *structMemberAllocator) StructMember() (v *Ydb.StructMember) {
   423  	v = structMemberPool.Get()
   424  	a.allocations = append(a.allocations, v)
   425  
   426  	return v
   427  }
   428  
   429  func (a *structMemberAllocator) free() {
   430  	for _, v := range a.allocations {
   431  		v.Reset()
   432  		structMemberPool.Put(v)
   433  	}
   434  	a.allocations = a.allocations[:0]
   435  }
   436  
   437  type textAllocator struct {
   438  	allocations []*Ydb.Value_TextValue
   439  }
   440  
   441  func (a *textAllocator) Text() (v *Ydb.Value_TextValue) {
   442  	v = textPool.Get()
   443  	a.allocations = append(a.allocations, v)
   444  
   445  	return v
   446  }
   447  
   448  func (a *textAllocator) free() {
   449  	for _, v := range a.allocations {
   450  		*v = Ydb.Value_TextValue{}
   451  		textPool.Put(v)
   452  	}
   453  	a.allocations = a.allocations[:0]
   454  }
   455  
   456  type tupleAllocator struct {
   457  	allocations []*Ydb.TupleType
   458  }
   459  
   460  func (a *tupleAllocator) Tuple() (v *Ydb.TupleType) {
   461  	v = tuplePool.Get()
   462  	a.allocations = append(a.allocations, v)
   463  
   464  	return v
   465  }
   466  
   467  func (a *tupleAllocator) free() {
   468  	for _, v := range a.allocations {
   469  		elements := v.GetElements()
   470  		for i := range elements {
   471  			elements[i] = nil
   472  		}
   473  		v.Reset()
   474  		v.Elements = elements[:0]
   475  		tuplePool.Put(v)
   476  	}
   477  	a.allocations = a.allocations[:0]
   478  }
   479  
   480  type typeDecimalAllocator struct {
   481  	allocations []*Ydb.Type_DecimalType
   482  }
   483  
   484  func (a *typeDecimalAllocator) TypeDecimal() (v *Ydb.Type_DecimalType) {
   485  	v = typeDecimalPool.Get()
   486  	a.allocations = append(a.allocations, v)
   487  
   488  	return v
   489  }
   490  
   491  func (a *typeDecimalAllocator) free() {
   492  	for _, v := range a.allocations {
   493  		*v = Ydb.Type_DecimalType{}
   494  		typeDecimalPool.Put(v)
   495  	}
   496  	a.allocations = a.allocations[:0]
   497  }
   498  
   499  type typeDictAllocator struct {
   500  	allocations []*Ydb.Type_DictType
   501  }
   502  
   503  func (a *typeDictAllocator) TypeDict() (v *Ydb.Type_DictType) {
   504  	v = typeDictPool.Get()
   505  	a.allocations = append(a.allocations, v)
   506  
   507  	return v
   508  }
   509  
   510  func (a *typeDictAllocator) free() {
   511  	for _, v := range a.allocations {
   512  		*v = Ydb.Type_DictType{}
   513  		typeDictPool.Put(v)
   514  	}
   515  	a.allocations = a.allocations[:0]
   516  }
   517  
   518  type typeEmptyListAllocator struct {
   519  	allocations []*Ydb.Type_EmptyListType
   520  }
   521  
   522  func (a *typeEmptyListAllocator) TypeEmptyList() (v *Ydb.Type_EmptyListType) {
   523  	v = typeEmptyListPool.Get()
   524  	a.allocations = append(a.allocations, v)
   525  
   526  	return v
   527  }
   528  
   529  func (a *typeEmptyListAllocator) free() {
   530  	for _, v := range a.allocations {
   531  		*v = Ydb.Type_EmptyListType{}
   532  		typeEmptyListPool.Put(v)
   533  	}
   534  	a.allocations = a.allocations[:0]
   535  }
   536  
   537  type typeEmptyDictAllocator struct {
   538  	allocations []*Ydb.Type_EmptyDictType
   539  }
   540  
   541  func (a *typeEmptyDictAllocator) TypeEmptyDict() (v *Ydb.Type_EmptyDictType) {
   542  	v = typeEmptyDictPool.Get()
   543  	a.allocations = append(a.allocations, v)
   544  
   545  	return v
   546  }
   547  
   548  func (a *typeEmptyDictAllocator) free() {
   549  	for _, v := range a.allocations {
   550  		*v = Ydb.Type_EmptyDictType{}
   551  		typeEmptyDictPool.Put(v)
   552  	}
   553  	a.allocations = a.allocations[:0]
   554  }
   555  
   556  type typeAllocator struct {
   557  	allocations []*Ydb.Type
   558  }
   559  
   560  func (a *typeAllocator) Type() (v *Ydb.Type) {
   561  	v = typePool.Get()
   562  	a.allocations = append(a.allocations, v)
   563  
   564  	return v
   565  }
   566  
   567  func (a *typeAllocator) free() {
   568  	for _, v := range a.allocations {
   569  		v.Reset()
   570  		typePool.Put(v)
   571  	}
   572  	a.allocations = a.allocations[:0]
   573  }
   574  
   575  type typeListAllocator struct {
   576  	allocations []*Ydb.Type_ListType
   577  }
   578  
   579  func (a *typeListAllocator) TypeList() (v *Ydb.Type_ListType) {
   580  	v = typeListPool.Get()
   581  	a.allocations = append(a.allocations, v)
   582  
   583  	return v
   584  }
   585  
   586  func (a *typeListAllocator) free() {
   587  	for _, v := range a.allocations {
   588  		*v = Ydb.Type_ListType{}
   589  		typeListPool.Put(v)
   590  	}
   591  	a.allocations = a.allocations[:0]
   592  }
   593  
   594  type typeOptionalAllocator struct {
   595  	allocations []*Ydb.Type_OptionalType
   596  }
   597  
   598  func (a *typeOptionalAllocator) TypeOptional() (v *Ydb.Type_OptionalType) {
   599  	v = typeOptionalPool.Get()
   600  	a.allocations = append(a.allocations, v)
   601  
   602  	return v
   603  }
   604  
   605  func (a *typeOptionalAllocator) free() {
   606  	for _, v := range a.allocations {
   607  		*v = Ydb.Type_OptionalType{}
   608  		typeOptionalPool.Put(v)
   609  	}
   610  	a.allocations = a.allocations[:0]
   611  }
   612  
   613  type typeStructAllocator struct {
   614  	allocations []*Ydb.Type_StructType
   615  }
   616  
   617  func (a *typeStructAllocator) TypeStruct() (v *Ydb.Type_StructType) {
   618  	v = typeStructPool.Get()
   619  	a.allocations = append(a.allocations, v)
   620  
   621  	return v
   622  }
   623  
   624  func (a *typeStructAllocator) free() {
   625  	for _, v := range a.allocations {
   626  		*v = Ydb.Type_StructType{}
   627  		typeStructPool.Put(v)
   628  	}
   629  	a.allocations = a.allocations[:0]
   630  }
   631  
   632  type typeTupleAllocator struct {
   633  	allocations []*Ydb.Type_TupleType
   634  }
   635  
   636  func (a *typeTupleAllocator) TypeTuple() (v *Ydb.Type_TupleType) {
   637  	v = typeTuplePool.Get()
   638  	a.allocations = append(a.allocations, v)
   639  
   640  	return v
   641  }
   642  
   643  func (a *typeTupleAllocator) free() {
   644  	for _, v := range a.allocations {
   645  		*v = Ydb.Type_TupleType{}
   646  		typeTuplePool.Put(v)
   647  	}
   648  	a.allocations = a.allocations[:0]
   649  }
   650  
   651  type typeVariantAllocator struct {
   652  	allocations []*Ydb.Type_VariantType
   653  }
   654  
   655  func (a *typeVariantAllocator) TypeVariant() (v *Ydb.Type_VariantType) {
   656  	v = typeVariantPool.Get()
   657  	a.allocations = append(a.allocations, v)
   658  
   659  	return v
   660  }
   661  
   662  func (a *typeVariantAllocator) free() {
   663  	for _, v := range a.allocations {
   664  		*v = Ydb.Type_VariantType{}
   665  		typeVariantPool.Put(v)
   666  	}
   667  	a.allocations = a.allocations[:0]
   668  }
   669  
   670  type typedValueAllocator struct {
   671  	allocations []*Ydb.TypedValue
   672  }
   673  
   674  func (a *typedValueAllocator) TypedValue() (v *Ydb.TypedValue) {
   675  	v = typedValuePool.Get()
   676  	a.allocations = append(a.allocations, v)
   677  
   678  	return v
   679  }
   680  
   681  func (a *typedValueAllocator) free() {
   682  	for _, v := range a.allocations {
   683  		v.Reset()
   684  		typedValuePool.Put(v)
   685  	}
   686  	a.allocations = a.allocations[:0]
   687  }
   688  
   689  type uint32Allocator struct {
   690  	allocations []*Ydb.Value_Uint32Value
   691  }
   692  
   693  func (a *uint32Allocator) Uint32() (v *Ydb.Value_Uint32Value) {
   694  	v = uint32Pool.Get()
   695  	a.allocations = append(a.allocations, v)
   696  
   697  	return v
   698  }
   699  
   700  func (a *uint32Allocator) free() {
   701  	for _, v := range a.allocations {
   702  		*v = Ydb.Value_Uint32Value{}
   703  		uint32Pool.Put(v)
   704  	}
   705  	a.allocations = a.allocations[:0]
   706  }
   707  
   708  type uint64Allocator struct {
   709  	allocations []*Ydb.Value_Uint64Value
   710  }
   711  
   712  func (a *uint64Allocator) Uint64() (v *Ydb.Value_Uint64Value) {
   713  	v = uint64Pool.Get()
   714  	a.allocations = append(a.allocations, v)
   715  
   716  	return v
   717  }
   718  
   719  func (a *uint64Allocator) free() {
   720  	for _, v := range a.allocations {
   721  		*v = Ydb.Value_Uint64Value{}
   722  		uint64Pool.Put(v)
   723  	}
   724  	a.allocations = a.allocations[:0]
   725  }
   726  
   727  type valueAllocator struct {
   728  	allocations []*Ydb.Value
   729  }
   730  
   731  func (a *valueAllocator) Value() (v *Ydb.Value) {
   732  	v = valuePool.Get()
   733  	a.allocations = append(a.allocations, v)
   734  
   735  	return v
   736  }
   737  
   738  func (a *valueAllocator) free() {
   739  	for _, v := range a.allocations {
   740  		items := v.GetItems()
   741  		pairs := v.GetPairs()
   742  		for i := range items {
   743  			items[i] = nil
   744  		}
   745  		for i := range pairs {
   746  			pairs[i] = nil
   747  		}
   748  		v.Reset()
   749  		v.Items = items[:0]
   750  		v.Pairs = pairs[:0]
   751  		valuePool.Put(v)
   752  	}
   753  	a.allocations = a.allocations[:0]
   754  }
   755  
   756  type variantAllocator struct {
   757  	allocations []*Ydb.VariantType
   758  }
   759  
   760  func (a *variantAllocator) Variant() (v *Ydb.VariantType) {
   761  	v = variantPool.Get()
   762  	a.allocations = append(a.allocations, v)
   763  
   764  	return v
   765  }
   766  
   767  func (a *variantAllocator) free() {
   768  	for _, v := range a.allocations {
   769  		variantPool.Put(v)
   770  	}
   771  	a.allocations = a.allocations[:0]
   772  }
   773  
   774  type variantStructItemsAllocator struct {
   775  	allocations []*Ydb.VariantType_StructItems
   776  }
   777  
   778  func (a *variantStructItemsAllocator) VariantStructItems() (v *Ydb.VariantType_StructItems) {
   779  	v = variantStructItemsPool.Get()
   780  	a.allocations = append(a.allocations, v)
   781  
   782  	return v
   783  }
   784  
   785  func (a *variantStructItemsAllocator) free() {
   786  	for _, v := range a.allocations {
   787  		variantStructItemsPool.Put(v)
   788  	}
   789  	a.allocations = a.allocations[:0]
   790  }
   791  
   792  type variantTupleItemsAllocator struct {
   793  	allocations []*Ydb.VariantType_TupleItems
   794  }
   795  
   796  func (a *variantTupleItemsAllocator) VariantTupleItems() (v *Ydb.VariantType_TupleItems) {
   797  	v = variantTupleItemsPool.Get()
   798  	a.allocations = append(a.allocations, v)
   799  
   800  	return v
   801  }
   802  
   803  func (a *variantTupleItemsAllocator) free() {
   804  	for _, v := range a.allocations {
   805  		variantTupleItemsPool.Put(v)
   806  	}
   807  	a.allocations = a.allocations[:0]
   808  }
   809  
   810  type tableExecuteQueryResultAllocator struct {
   811  	allocations []*Ydb_Table.ExecuteQueryResult
   812  }
   813  
   814  func (a *tableExecuteQueryResultAllocator) TableExecuteQueryResult() (v *Ydb_Table.ExecuteQueryResult) {
   815  	v = tableExecuteQueryResultPool.Get()
   816  	a.allocations = append(a.allocations, v)
   817  
   818  	return v
   819  }
   820  
   821  func (a *tableExecuteQueryResultAllocator) free() {
   822  	for _, v := range a.allocations {
   823  		v.Reset()
   824  		tableExecuteQueryResultPool.Put(v)
   825  	}
   826  	a.allocations = a.allocations[:0]
   827  }
   828  
   829  type tableExecuteQueryRequestAllocator struct {
   830  	allocations []*Ydb_Table.ExecuteDataQueryRequest
   831  }
   832  
   833  func (a *tableExecuteQueryRequestAllocator) TableExecuteDataQueryRequest() (v *Ydb_Table.ExecuteDataQueryRequest) {
   834  	v = tableExecuteDataQueryRequestPool.Get()
   835  	a.allocations = append(a.allocations, v)
   836  
   837  	return v
   838  }
   839  
   840  func (a *tableExecuteQueryRequestAllocator) free() {
   841  	for _, v := range a.allocations {
   842  		v.Reset()
   843  		tableExecuteDataQueryRequestPool.Put(v)
   844  	}
   845  	a.allocations = a.allocations[:0]
   846  }
   847  
   848  type tableQueryCachePolicyAllocator struct {
   849  	allocations []*Ydb_Table.QueryCachePolicy
   850  }
   851  
   852  func (a *tableQueryCachePolicyAllocator) TableQueryCachePolicy() (v *Ydb_Table.QueryCachePolicy) {
   853  	v = tableQueryCachePolicyPool.Get()
   854  	a.allocations = append(a.allocations, v)
   855  
   856  	return v
   857  }
   858  
   859  func (a *tableQueryCachePolicyAllocator) free() {
   860  	for _, v := range a.allocations {
   861  		v.Reset()
   862  		tableQueryCachePolicyPool.Put(v)
   863  	}
   864  	a.allocations = a.allocations[:0]
   865  }
   866  
   867  type tableQueryAllocator struct {
   868  	allocations []*Ydb_Table.Query
   869  }
   870  
   871  func (a *tableQueryAllocator) TableQuery() (v *Ydb_Table.Query) {
   872  	v = tableQueryPool.Get()
   873  	a.allocations = append(a.allocations, v)
   874  
   875  	return v
   876  }
   877  
   878  func (a *tableQueryAllocator) free() {
   879  	for _, v := range a.allocations {
   880  		v.Reset()
   881  		tableQueryPool.Put(v)
   882  	}
   883  	a.allocations = a.allocations[:0]
   884  }
   885  
   886  type tableQueryYqlTextAllocator struct {
   887  	allocations []*Ydb_Table.Query_YqlText
   888  }
   889  
   890  func (a *tableQueryYqlTextAllocator) TableQueryYqlText(s string) (v *Ydb_Table.Query_YqlText) {
   891  	v = tableQueryYqlTextPool.Get()
   892  	v.YqlText = s
   893  	a.allocations = append(a.allocations, v)
   894  
   895  	return v
   896  }
   897  
   898  func (a *tableQueryYqlTextAllocator) free() {
   899  	for _, v := range a.allocations {
   900  		tableQueryYqlTextPool.Put(v)
   901  	}
   902  	a.allocations = a.allocations[:0]
   903  }
   904  
   905  type tableQueryIDAllocator struct {
   906  	allocations []*Ydb_Table.Query_Id
   907  }
   908  
   909  func (a *tableQueryIDAllocator) TableQueryID(id string) (v *Ydb_Table.Query_Id) {
   910  	v = tableQueryIDPool.Get()
   911  	v.Id = id
   912  	a.allocations = append(a.allocations, v)
   913  
   914  	return v
   915  }
   916  
   917  func (a *tableQueryIDAllocator) free() {
   918  	for _, v := range a.allocations {
   919  		tableQueryIDPool.Put(v)
   920  	}
   921  	a.allocations = a.allocations[:0]
   922  }
   923  
   924  type queryExecuteQueryRequestAllocator struct {
   925  	allocations []*Ydb_Query.ExecuteQueryRequest
   926  }
   927  
   928  func (a *queryExecuteQueryRequestAllocator) QueryExecuteQueryRequest() (
   929  	v *Ydb_Query.ExecuteQueryRequest,
   930  ) {
   931  	v = queryExecuteQueryRequestPool.Get()
   932  	a.allocations = append(a.allocations, v)
   933  
   934  	return v
   935  }
   936  
   937  func (a *queryExecuteQueryRequestAllocator) free() {
   938  	for _, v := range a.allocations {
   939  		v.Reset()
   940  		queryExecuteQueryRequestPool.Put(v)
   941  	}
   942  	a.allocations = a.allocations[:0]
   943  }
   944  
   945  type queryExecuteQueryResponsePartAllocator struct {
   946  	allocations []*Ydb_Query.ExecuteQueryResponsePart
   947  }
   948  
   949  func (a *queryExecuteQueryResponsePartAllocator) QueryExecuteQueryResponsePart() (
   950  	v *Ydb_Query.ExecuteQueryResponsePart,
   951  ) {
   952  	v = queryExecuteQueryResponsePartPool.Get()
   953  	a.allocations = append(a.allocations, v)
   954  
   955  	return v
   956  }
   957  
   958  func (a *queryExecuteQueryResponsePartAllocator) free() {
   959  	for _, v := range a.allocations {
   960  		v.Reset()
   961  		queryExecuteQueryResponsePartPool.Put(v)
   962  	}
   963  	a.allocations = a.allocations[:0]
   964  }
   965  
   966  type queryExecuteQueryRequestQueryContentAllocator struct {
   967  	allocations []*Ydb_Query.ExecuteQueryRequest_QueryContent
   968  }
   969  
   970  func (a *queryExecuteQueryRequestQueryContentAllocator) QueryExecuteQueryRequestQueryContent() (
   971  	v *Ydb_Query.ExecuteQueryRequest_QueryContent,
   972  ) {
   973  	v = queryExecuteQueryRequestQueryContentPool.Get()
   974  	a.allocations = append(a.allocations, v)
   975  
   976  	return v
   977  }
   978  
   979  func (a *queryExecuteQueryRequestQueryContentAllocator) free() {
   980  	for _, v := range a.allocations {
   981  		queryExecuteQueryRequestQueryContentPool.Put(v)
   982  	}
   983  	a.allocations = a.allocations[:0]
   984  }
   985  
   986  type queryTransactionControlAllocator struct {
   987  	allocations []*Ydb_Query.TransactionControl
   988  }
   989  
   990  func (a *queryTransactionControlAllocator) QueryTransactionControl() (v *Ydb_Query.TransactionControl) {
   991  	v = queryTransactionControlPool.Get()
   992  	a.allocations = append(a.allocations, v)
   993  
   994  	return v
   995  }
   996  
   997  func (a *queryTransactionControlAllocator) free() {
   998  	for _, v := range a.allocations {
   999  		v.Reset()
  1000  		queryTransactionControlPool.Put(v)
  1001  	}
  1002  	a.allocations = a.allocations[:0]
  1003  }
  1004  
  1005  type queryTransactionControlBeginTxAllocator struct {
  1006  	allocations []*Ydb_Query.TransactionControl_BeginTx
  1007  }
  1008  
  1009  func (a *queryTransactionControlBeginTxAllocator) QueryTransactionControlBeginTx() (
  1010  	v *Ydb_Query.TransactionControl_BeginTx,
  1011  ) {
  1012  	v = queryTransactionControlBeginTxPool.Get()
  1013  	a.allocations = append(a.allocations, v)
  1014  
  1015  	return v
  1016  }
  1017  
  1018  func (a *queryTransactionControlBeginTxAllocator) free() {
  1019  	for _, v := range a.allocations {
  1020  		queryTransactionControlBeginTxPool.Put(v)
  1021  	}
  1022  	a.allocations = a.allocations[:0]
  1023  }
  1024  
  1025  type queryTransactionControlTxIDAllocator struct {
  1026  	allocations []*Ydb_Query.TransactionControl_TxId
  1027  }
  1028  
  1029  func (a *queryTransactionControlTxIDAllocator) QueryTransactionControlTxID() (v *Ydb_Query.TransactionControl_TxId) {
  1030  	v = queryTransactionControlTxIDPool.Get()
  1031  	a.allocations = append(a.allocations, v)
  1032  
  1033  	return v
  1034  }
  1035  
  1036  func (a *queryTransactionControlTxIDAllocator) free() {
  1037  	for _, v := range a.allocations {
  1038  		queryTransactionControlTxIDPool.Put(v)
  1039  	}
  1040  	a.allocations = a.allocations[:0]
  1041  }
  1042  
  1043  type queryTransactionSettingsAllocator struct {
  1044  	allocations []*Ydb_Query.TransactionSettings
  1045  }
  1046  
  1047  func (a *queryTransactionSettingsAllocator) QueryTransactionSettings() (v *Ydb_Query.TransactionSettings) {
  1048  	v = queryTransactionSettingsPool.Get()
  1049  	a.allocations = append(a.allocations, v)
  1050  
  1051  	return v
  1052  }
  1053  
  1054  func (a *queryTransactionSettingsAllocator) free() {
  1055  	for _, v := range a.allocations {
  1056  		v.Reset()
  1057  		queryTransactionSettingsPool.Put(v)
  1058  	}
  1059  	a.allocations = a.allocations[:0]
  1060  }
  1061  
  1062  type queryTransactionSettingsSerializableReadWriteAllocator struct {
  1063  	allocations []*Ydb_Query.TransactionSettings_SerializableReadWrite
  1064  }
  1065  
  1066  func (a *queryTransactionSettingsSerializableReadWriteAllocator) QueryTransactionSettingsSerializableReadWrite() (
  1067  	v *Ydb_Query.TransactionSettings_SerializableReadWrite,
  1068  ) {
  1069  	v = queryTransactionSettingsSerializableReadWritePool.Get()
  1070  	a.allocations = append(a.allocations, v)
  1071  
  1072  	return v
  1073  }
  1074  
  1075  func (a *queryTransactionSettingsSerializableReadWriteAllocator) free() {
  1076  	for _, v := range a.allocations {
  1077  		queryTransactionSettingsSerializableReadWritePool.Put(v)
  1078  	}
  1079  	a.allocations = a.allocations[:0]
  1080  }
  1081  
  1082  type queryQueryContentAllocator struct {
  1083  	allocations []*Ydb_Query.QueryContent
  1084  }
  1085  
  1086  func (a *queryQueryContentAllocator) QueryQueryContent() (v *Ydb_Query.QueryContent) {
  1087  	v = queryQueryContentPool.Get()
  1088  	a.allocations = append(a.allocations, v)
  1089  
  1090  	return v
  1091  }
  1092  
  1093  func (a *queryQueryContentAllocator) free() {
  1094  	for _, v := range a.allocations {
  1095  		v.Reset()
  1096  		queryQueryContentPool.Put(v)
  1097  	}
  1098  	a.allocations = a.allocations[:0]
  1099  }
  1100  
  1101  type Pool[T any] sync.Pool
  1102  
  1103  func (p *Pool[T]) Get() *T {
  1104  	v := (*sync.Pool)(p).Get()
  1105  	if v == nil {
  1106  		var zero T
  1107  		v = &zero
  1108  	}
  1109  
  1110  	return v.(*T)
  1111  }
  1112  
  1113  func (p *Pool[T]) Put(t *T) {
  1114  	(*sync.Pool)(p).Put(t)
  1115  }
  1116  
  1117  var (
  1118  	allocatorPool                                     Pool[Allocator]
  1119  	valuePool                                         Pool[Ydb.Value]
  1120  	typePool                                          Pool[Ydb.Type]
  1121  	typeDecimalPool                                   Pool[Ydb.Type_DecimalType]
  1122  	typeListPool                                      Pool[Ydb.Type_ListType]
  1123  	typeEmptyListPool                                 Pool[Ydb.Type_EmptyListType]
  1124  	typeEmptyDictPool                                 Pool[Ydb.Type_EmptyDictType]
  1125  	typeTuplePool                                     Pool[Ydb.Type_TupleType]
  1126  	typeStructPool                                    Pool[Ydb.Type_StructType]
  1127  	typeDictPool                                      Pool[Ydb.Type_DictType]
  1128  	typeVariantPool                                   Pool[Ydb.Type_VariantType]
  1129  	decimalPool                                       Pool[Ydb.DecimalType]
  1130  	listPool                                          Pool[Ydb.ListType]
  1131  	tuplePool                                         Pool[Ydb.TupleType]
  1132  	structPool                                        Pool[Ydb.StructType]
  1133  	dictPool                                          Pool[Ydb.DictType]
  1134  	variantPool                                       Pool[Ydb.VariantType]
  1135  	variantTupleItemsPool                             Pool[Ydb.VariantType_TupleItems]
  1136  	variantStructItemsPool                            Pool[Ydb.VariantType_StructItems]
  1137  	structMemberPool                                  Pool[Ydb.StructMember]
  1138  	typeOptionalPool                                  Pool[Ydb.Type_OptionalType]
  1139  	optionalPool                                      Pool[Ydb.OptionalType]
  1140  	typedValuePool                                    Pool[Ydb.TypedValue]
  1141  	boolPool                                          Pool[Ydb.Value_BoolValue]
  1142  	bytesPool                                         Pool[Ydb.Value_BytesValue]
  1143  	textPool                                          Pool[Ydb.Value_TextValue]
  1144  	int32Pool                                         Pool[Ydb.Value_Int32Value]
  1145  	uint32Pool                                        Pool[Ydb.Value_Uint32Value]
  1146  	low128Pool                                        Pool[Ydb.Value_Low_128]
  1147  	int64Pool                                         Pool[Ydb.Value_Int64Value]
  1148  	uint64Pool                                        Pool[Ydb.Value_Uint64Value]
  1149  	floatPool                                         Pool[Ydb.Value_FloatValue]
  1150  	doublePool                                        Pool[Ydb.Value_DoubleValue]
  1151  	nestedPool                                        Pool[Ydb.Value_NestedValue]
  1152  	nullFlagPool                                      Pool[Ydb.Value_NullFlagValue]
  1153  	pairPool                                          Pool[Ydb.ValuePair]
  1154  	tableExecuteQueryResultPool                       Pool[Ydb_Table.ExecuteQueryResult]
  1155  	tableExecuteDataQueryRequestPool                  Pool[Ydb_Table.ExecuteDataQueryRequest]
  1156  	tableQueryCachePolicyPool                         Pool[Ydb_Table.QueryCachePolicy]
  1157  	tableQueryPool                                    Pool[Ydb_Table.Query]
  1158  	tableQueryYqlTextPool                             Pool[Ydb_Table.Query_YqlText]
  1159  	tableQueryIDPool                                  Pool[Ydb_Table.Query_Id]
  1160  	queryExecuteQueryRequestPool                      Pool[Ydb_Query.ExecuteQueryRequest]
  1161  	queryExecuteQueryRequestQueryContentPool          Pool[Ydb_Query.ExecuteQueryRequest_QueryContent]
  1162  	queryExecuteQueryResponsePartPool                 Pool[Ydb_Query.ExecuteQueryResponsePart]
  1163  	queryQueryContentPool                             Pool[Ydb_Query.QueryContent]
  1164  	queryTransactionControlPool                       Pool[Ydb_Query.TransactionControl]
  1165  	queryTransactionControlBeginTxPool                Pool[Ydb_Query.TransactionControl_BeginTx]
  1166  	queryTransactionControlTxIDPool                   Pool[Ydb_Query.TransactionControl_TxId]
  1167  	queryTransactionSettingsPool                      Pool[Ydb_Query.TransactionSettings]
  1168  	queryTransactionSettingsSerializableReadWritePool Pool[Ydb_Query.TransactionSettings_SerializableReadWrite]
  1169  )