@@ -172,55 +172,51 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
172
172
}
173
173
out := make ([]interface {}, 0 , int (math .Max (float64 (rLen ), float64 (lLen ))))
174
174
175
- // TODO: ordering is totally wrong.
176
- // TODO: might as well make the map order work the same way.
175
+ lhsOrder := make ([]fieldpath.PathElement , 0 , lLen )
177
176
178
- // This is a cheap hack to at least make the output order stable.
179
- rhsOrder := make ([]fieldpath.PathElement , 0 , rLen )
180
-
181
- // First, collect all RHS children.
182
- observedRHS := fieldpath .MakePathElementValueMap (rLen )
183
- if rhs != nil {
184
- for i := 0 ; i < rhs .Length (); i ++ {
185
- child := rhs .At (i )
177
+ // First, collect all LHS children.
178
+ observedLHS := fieldpath .MakePathElementValueMap (lLen )
179
+ if lhs != nil {
180
+ for i := 0 ; i < lhs .Length (); i ++ {
181
+ child := lhs .At (i )
186
182
pe , err := listItemToPathElement (w .allocator , w .schema , t , i , child )
187
183
if err != nil {
188
- errs = append (errs , errorf ("rhs : element %v: %v" , i , err .Error ())... )
184
+ errs = append (errs , errorf ("lhs : element %v: %v" , i , err .Error ())... )
189
185
// If we can't construct the path element, we can't
190
186
// even report errors deeper in the schema, so bail on
191
187
// this element.
192
188
continue
193
189
}
194
- if _ , ok := observedRHS .Get (pe ); ok {
195
- errs = append (errs , errorf ("rhs : duplicate entries for key %v" , pe .String ())... )
190
+ if _ , ok := observedLHS .Get (pe ); ok {
191
+ errs = append (errs , errorf ("lhs : duplicate entries for key %v" , pe .String ())... )
196
192
}
197
- observedRHS .Insert (pe , child )
198
- rhsOrder = append (rhsOrder , pe )
193
+ observedLHS .Insert (pe , child )
194
+ lhsOrder = append (lhsOrder , pe )
199
195
}
200
196
}
201
197
202
- // Then merge with LHS children.
203
- observedLHS := fieldpath .MakePathElementSet (lLen )
204
- if lhs != nil {
205
- for i := 0 ; i < lhs .Length (); i ++ {
206
- child := lhs .At (i )
198
+ // Then merge with RHS children.
199
+ observedRHS := fieldpath .MakePathElementSet (rLen )
200
+ if rhs != nil {
201
+ for i := 0 ; i < rhs .Length (); i ++ {
202
+ child := rhs .At (i )
207
203
pe , err := listItemToPathElement (w .allocator , w .schema , t , i , child )
208
204
if err != nil {
209
- errs = append (errs , errorf ("lhs : element %v: %v" , i , err .Error ())... )
205
+ errs = append (errs , errorf ("rhs : element %v: %v" , i , err .Error ())... )
210
206
// If we can't construct the path element, we can't
211
207
// even report errors deeper in the schema, so bail on
212
208
// this element.
213
209
continue
214
210
}
215
- if observedLHS .Has (pe ) {
216
- errs = append (errs , errorf ("lhs : duplicate entries for key %v" , pe .String ())... )
211
+ if observedRHS .Has (pe ) {
212
+ errs = append (errs , errorf ("rhs : duplicate entries for key %v" , pe .String ())... )
217
213
continue
218
214
}
219
- observedLHS .Insert (pe )
215
+ observedRHS .Insert (pe )
220
216
w2 := w .prepareDescent (pe , t .ElementType )
221
- w2 .lhs = value . Value ( child )
222
- if rchild , ok := observedRHS .Get (pe ); ok {
223
- w2 .rhs = rchild
217
+ w2 .rhs = child
218
+ if lchild , ok := observedLHS .Get (pe ); ok {
219
+ w2 .lhs = lchild
224
220
}
225
221
errs = append (errs , w2 .merge (pe .String )... )
226
222
if w2 .out != nil {
@@ -230,13 +226,13 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
230
226
}
231
227
}
232
228
233
- for _ , pe := range rhsOrder {
234
- if observedLHS .Has (pe ) {
229
+ for _ , pe := range lhsOrder {
230
+ if observedRHS .Has (pe ) {
235
231
continue
236
232
}
237
- value , _ := observedRHS .Get (pe )
233
+ value , _ := observedLHS .Get (pe )
238
234
w2 := w .prepareDescent (pe , t .ElementType )
239
- w2 .rhs = value
235
+ w2 .lhs = value
240
236
errs = append (errs , w2 .merge (pe .String )... )
241
237
if w2 .out != nil {
242
238
out = append (out , * w2 .out )
0 commit comments