@@ -48,6 +48,8 @@ type mergingWalker struct {
4848
4949 // Allocate only as many walkers as needed for the depth by storing them here.
5050 spareWalkers * []* mergingWalker
51+
52+ allocator value.Allocator
5153}
5254
5355// merge rules examine w.lhs and w.rhs (up to one of which may be nil) and
@@ -152,7 +154,7 @@ func (w *mergingWalker) derefMap(prefix string, v value.Value) (value.Map, Valid
152154 if v == nil {
153155 return nil , nil
154156 }
155- m , err := mapValue (v )
157+ m , err := mapValue (w . allocator , v )
156158 if err != nil {
157159 return nil , errorf ("%v: %v" , prefix , err )
158160 }
@@ -181,7 +183,7 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
181183 if rhs != nil {
182184 for i := 0 ; i < rhs .Length (); i ++ {
183185 child := rhs .At (i )
184- pe , err := listItemToPathElement (t , i , child )
186+ pe , err := listItemToPathElement (w . allocator , t , i , child )
185187 if err != nil {
186188 errs = append (errs , errorf ("rhs: element %v: %v" , i , err .Error ())... )
187189 // If we can't construct the path element, we can't
@@ -202,7 +204,7 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
202204 if lhs != nil {
203205 for i := 0 ; i < lhs .Length (); i ++ {
204206 child := lhs .At (i )
205- pe , err := listItemToPathElement (t , i , child )
207+ pe , err := listItemToPathElement (w . allocator , t , i , child )
206208 if err != nil {
207209 errs = append (errs , errorf ("lhs: element %v: %v" , i , err .Error ())... )
208210 // If we can't construct the path element, we can't
@@ -254,7 +256,7 @@ func (w *mergingWalker) derefList(prefix string, v value.Value) (value.List, Val
254256 if v == nil {
255257 return nil , nil
256258 }
257- l , err := listValue (v )
259+ l , err := listValue (w . allocator , v )
258260 if err != nil {
259261 return nil , errorf ("%v: %v" , prefix , err )
260262 }
@@ -264,11 +266,11 @@ func (w *mergingWalker) derefList(prefix string, v value.Value) (value.List, Val
264266func (w * mergingWalker ) doList (t * schema.List ) (errs ValidationErrors ) {
265267 lhs , _ := w .derefList ("lhs: " , w .lhs )
266268 if lhs != nil {
267- defer lhs . Recycle ( )
269+ defer w . allocator . Free ( lhs )
268270 }
269271 rhs , _ := w .derefList ("rhs: " , w .rhs )
270272 if rhs != nil {
271- defer rhs . Recycle ( )
273+ defer w . allocator . Free ( rhs )
272274 }
273275
274276 // If both lhs and rhs are empty/null, treat it as a
@@ -310,7 +312,7 @@ func (w *mergingWalker) visitMapItem(t *schema.Map, out map[string]interface{},
310312func (w * mergingWalker ) visitMapItems (t * schema.Map , lhs , rhs value.Map ) (errs ValidationErrors ) {
311313 out := map [string ]interface {}{}
312314
313- value .MapZip ( lhs , rhs , value .Unordered , func (key string , lhsValue , rhsValue value.Value ) bool {
315+ value .MapZipUsing ( w . allocator , lhs , rhs , value .Unordered , func (key string , lhsValue , rhsValue value.Value ) bool {
314316 errs = append (errs , w .visitMapItem (t , out , key , lhsValue , rhsValue )... )
315317 return true
316318 })
@@ -325,11 +327,11 @@ func (w *mergingWalker) visitMapItems(t *schema.Map, lhs, rhs value.Map) (errs V
325327func (w * mergingWalker ) doMap (t * schema.Map ) (errs ValidationErrors ) {
326328 lhs , _ := w .derefMap ("lhs: " , w .lhs )
327329 if lhs != nil {
328- defer lhs . Recycle ( )
330+ defer w . allocator . Free ( lhs )
329331 }
330332 rhs , _ := w .derefMap ("rhs: " , w .rhs )
331333 if rhs != nil {
332- defer rhs . Recycle ( )
334+ defer w . allocator . Free ( rhs )
333335 }
334336 // If both lhs and rhs are empty/null, treat it as a
335337 // leaf: this helps preserve the empty/null
0 commit comments