File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -502,6 +502,19 @@ type StructValueProto struct {
502502 Values []* Ydb.Value
503503}
504504
505+ func (s * StructValueProto ) Grow (size int ) {
506+ if cap (s .Fields ) < size {
507+ newFields := make ([]StructField , 0 , size )
508+ newFields = append (newFields , s .Fields ... )
509+ s .Fields = newFields
510+ }
511+ if cap (s .Values ) < size {
512+ newValues := make ([]* Ydb.Value , 0 , size )
513+ newValues = append (newValues , s .Values ... )
514+ s .Values = newValues
515+ }
516+ }
517+
505518func (s * StructValueProto ) Add (name string , value V ) {
506519 s .Fields = append (s .Fields , StructField {
507520 Name : name ,
Original file line number Diff line number Diff line change @@ -147,18 +147,28 @@ func ListValue(vs ...Value) Value {
147147
148148type tStructValueProto value.StructValueProto
149149
150- type StructValueOption func (* tStructValueProto )
150+ type StructValueOption interface {
151+ apply (* tStructValueProto )
152+ }
153+
154+ type structField struct {
155+ name string
156+ value Value
157+ }
158+
159+ func (f structField ) apply (p * tStructValueProto ) {
160+ (* value .StructValueProto )(p ).Add (f .name , f .value )
161+ }
151162
152163func StructFieldValue (name string , v Value ) StructValueOption {
153- return func (p * tStructValueProto ) {
154- (* value .StructValueProto )(p ).Add (name , v )
155- }
164+ return structField {name : name , value : v }
156165}
157166
158167func StructValue (opts ... StructValueOption ) Value {
159168 var p tStructValueProto
169+ (* value .StructValueProto )(& p ).Grow (len (opts ))
160170 for _ , opt := range opts {
161- opt (& p )
171+ opt . apply (& p )
162172 }
163173 return value .StructValue ((* value .StructValueProto )(& p ))
164174}
You can’t perform that action at this time.
0 commit comments