@@ -197,6 +197,8 @@ static void AddDiffResult(
197
197
internal static bool MatchArrayItem ( ref ArrayItemMatchContext context , JsonDiffOptions ? options ,
198
198
in JsonComparerOptions comparerOptions )
199
199
{
200
+ // Prefer DeepEquals because LCS is weighted as per deep equality, and deep equality
201
+ // usually generates smaller diff
200
202
if ( context . Left . DeepEquals ( context . Right , comparerOptions ) )
201
203
{
202
204
context . DeepEqual ( ) ;
@@ -206,7 +208,7 @@ internal static bool MatchArrayItem(ref ArrayItemMatchContext context, JsonDiffO
206
208
if ( options is not null && context . Left is JsonObject or JsonArray &&
207
209
context . Right is JsonObject or JsonArray )
208
210
{
209
- if ( FuzzyMatchArrayItem ( ref context , options , out var fuzzyResult ) )
211
+ if ( FallbackMatchArrayItem ( ref context , options , out var fuzzyResult ) )
210
212
{
211
213
return fuzzyResult ;
212
214
}
@@ -220,7 +222,7 @@ internal static bool MatchArrayItem(ref ArrayItemMatchContext context, JsonDiffO
220
222
return false ;
221
223
}
222
224
223
- internal static bool MatchArrayItem (
225
+ internal static bool MatchArrayValueItem (
224
226
ref ArrayItemMatchContext context ,
225
227
ref JsonValueWrapper wrapperLeft ,
226
228
ref JsonValueWrapper wrapperRight ,
@@ -241,11 +243,12 @@ internal static bool MatchArrayItem(
241
243
return false ;
242
244
}
243
245
244
- private static bool FuzzyMatchArrayItem ( ref ArrayItemMatchContext context , JsonDiffOptions options ,
246
+ private static bool FallbackMatchArrayItem ( ref ArrayItemMatchContext context , JsonDiffOptions options ,
245
247
out bool result )
246
248
{
247
249
result = false ;
248
250
251
+ // Scenario 1: keyed objects or arrays
249
252
var keyFinder = options . ArrayObjectItemKeyFinder ;
250
253
if ( keyFinder is not null )
251
254
{
@@ -254,25 +257,28 @@ private static bool FuzzyMatchArrayItem(ref ArrayItemMatchContext context, JsonD
254
257
255
258
if ( keyX is null && keyY is null )
256
259
{
257
- // Use DeepEquals if both items are not keyed
258
260
return false ;
259
261
}
260
262
261
263
result = Equals ( keyX , keyY ) ;
262
264
return true ;
263
265
}
264
266
267
+ // Scenario 2: match objects or arrays by position in parent array
265
268
if ( options . ArrayObjectItemMatchByPosition )
266
269
{
267
270
if ( context . LeftPosition == context . RightPosition )
268
271
{
269
272
result = true ;
270
273
return true ;
271
274
}
275
+ }
272
276
273
- // We don't return a result for objects at different position
274
- // so that we could still compare them using DeepEquals, or
275
- // return "not equal" if this method is called after.
277
+ // Scenario 3: force a later diff operation when property filter is set
278
+ if ( options . PropertyFilter is not null )
279
+ {
280
+ result = true ;
281
+ return true ;
276
282
}
277
283
278
284
return false ;
0 commit comments