@@ -168,7 +168,7 @@ func (w *mergingWalker) visitListItems(t schema.List, lhs, rhs *value.List) (err
168
168
rhsOrder := []fieldpath.PathElement {}
169
169
170
170
// First, collect all RHS children.
171
- observedRHS := map [ string ]value. Value {}
171
+ observedRHS := fieldpath. PathElementValueMap {}
172
172
if rhs != nil {
173
173
for i , child := range rhs .Items {
174
174
pe , err := listItemToPathElement (t , i , child )
@@ -179,17 +179,16 @@ func (w *mergingWalker) visitListItems(t schema.List, lhs, rhs *value.List) (err
179
179
// this element.
180
180
continue
181
181
}
182
- keyStr := pe .String ()
183
- if _ , found := observedRHS [keyStr ]; found {
184
- errs = append (errs , w .errorf ("rhs: duplicate entries for key %v" , keyStr )... )
182
+ if _ , ok := observedRHS .Get (pe ); ok {
183
+ errs = append (errs , w .errorf ("rhs: duplicate entries for key %v" , pe .String ())... )
185
184
}
186
- observedRHS [ keyStr ] = child
185
+ observedRHS . Insert ( pe , child )
187
186
rhsOrder = append (rhsOrder , pe )
188
187
}
189
188
}
190
189
191
190
// Then merge with LHS children.
192
- observedLHS := map [ string ] struct {} {}
191
+ observedLHS := fieldpath. PathElementSet {}
193
192
if lhs != nil {
194
193
for i , child := range lhs .Items {
195
194
pe , err := listItemToPathElement (t , i , child )
@@ -200,15 +199,14 @@ func (w *mergingWalker) visitListItems(t schema.List, lhs, rhs *value.List) (err
200
199
// this element.
201
200
continue
202
201
}
203
- keyStr := pe .String ()
204
- if _ , found := observedLHS [keyStr ]; found {
205
- errs = append (errs , w .errorf ("lhs: duplicate entries for key %v" , keyStr )... )
202
+ if observedLHS .Has (pe ) {
203
+ errs = append (errs , w .errorf ("lhs: duplicate entries for key %v" , pe .String ())... )
206
204
continue
207
205
}
208
- observedLHS [ keyStr ] = struct {}{}
206
+ observedLHS . Insert ( pe )
209
207
w2 := w .prepareDescent (pe , t .ElementType )
210
208
w2 .lhs = & child
211
- if rchild , ok := observedRHS [ keyStr ] ; ok {
209
+ if rchild , ok := observedRHS . Get ( pe ) ; ok {
212
210
w2 .rhs = & rchild
213
211
}
214
212
if newErrs := w2 .merge (); len (newErrs ) > 0 {
@@ -217,22 +215,22 @@ func (w *mergingWalker) visitListItems(t schema.List, lhs, rhs *value.List) (err
217
215
out .Items = append (out .Items , * w2 .out )
218
216
}
219
217
w .finishDescent (w2 )
220
- // Keep track of children that have been handled
221
- delete (observedRHS , keyStr )
222
218
}
223
219
}
224
220
225
- for _ , rhsToCheck := range rhsOrder {
226
- if unmergedChild , ok := observedRHS [rhsToCheck .String ()]; ok {
227
- w2 := w .prepareDescent (rhsToCheck , t .ElementType )
228
- w2 .rhs = & unmergedChild
229
- if newErrs := w2 .merge (); len (newErrs ) > 0 {
230
- errs = append (errs , newErrs ... )
231
- } else if w2 .out != nil {
232
- out .Items = append (out .Items , * w2 .out )
233
- }
234
- w .finishDescent (w2 )
221
+ for _ , pe := range rhsOrder {
222
+ if observedLHS .Has (pe ) {
223
+ continue
224
+ }
225
+ value , _ := observedRHS .Get (pe )
226
+ w2 := w .prepareDescent (pe , t .ElementType )
227
+ w2 .rhs = & value
228
+ if newErrs := w2 .merge (); len (newErrs ) > 0 {
229
+ errs = append (errs , newErrs ... )
230
+ } else if w2 .out != nil {
231
+ out .Items = append (out .Items , * w2 .out )
235
232
}
233
+ w .finishDescent (w2 )
236
234
}
237
235
238
236
if len (out .Items ) > 0 {
0 commit comments