@@ -113,6 +113,8 @@ final class Differ
113113 'ignoreWhitespace ' => false ,
114114 // if the input sequence is too long, it will just gives up (especially for char-level diff)
115115 'lengthLimit ' => 2000 ,
116+ // if truthy, when inputs are identical, the whole inputs will be rendered in the output
117+ 'fullContextIfIdentical ' => false ,
116118 ];
117119
118120 /**
@@ -310,10 +312,21 @@ public function getGroupedOpcodes(): array
310312 return $ this ->groupedOpcodes ;
311313 }
312314
313- $ this ->getGroupedOpcodesPre ($ this ->old , $ this ->new );
315+ $ old = $ this ->old ;
316+ $ new = $ this ->new ;
317+
318+ if ($ this ->oldNewComparison === 0 && $ this ->options ['fullContextIfIdentical ' ]) {
319+ return [
320+ [
321+ [SequenceMatcher::OP_EQ , 0 , \count ($ old ), 0 , \count ($ new )],
322+ ],
323+ ];
324+ }
325+
326+ $ this ->getGroupedOpcodesPre ($ old , $ new );
314327
315328 $ opcodes = $ this ->sequenceMatcher
316- ->setSequences ($ this -> old , $ this -> new )
329+ ->setSequences ($ old , $ new )
317330 ->getGroupedOpcodes ($ this ->options ['context ' ])
318331 ;
319332
@@ -335,10 +348,21 @@ public function getGroupedOpcodesGnu(): array
335348 return $ this ->groupedOpcodesGnu ;
336349 }
337350
338- $ this ->getGroupedOpcodesGnuPre ($ this ->old , $ this ->new );
351+ $ old = $ this ->old ;
352+ $ new = $ this ->new ;
353+
354+ if ($ this ->oldNewComparison === 0 && $ this ->options ['fullContextIfIdentical ' ]) {
355+ return [
356+ [
357+ [SequenceMatcher::OP_EQ , 0 , \count ($ old ), 0 , \count ($ new )],
358+ ],
359+ ];
360+ }
361+
362+ $ this ->getGroupedOpcodesGnuPre ($ old , $ new );
339363
340364 $ opcodes = $ this ->sequenceMatcher
341- ->setSequences ($ this -> old , $ this -> new )
365+ ->setSequences ($ old , $ new )
342366 ->getGroupedOpcodes ($ this ->options ['context ' ])
343367 ;
344368
0 commit comments