| | $n = count($newLines); |
| | |
| | - // LCS Algorithm |
| | + // LCS Algorithm Optimization: Trim matching start/end |
| | $start = 0; |
| | while ($start < $m && $start < $n && $oldLines[$start] === $newLines[$start]) { |
 |
| | $oldSlice = array_slice($oldLines, $start, $m - $start - $end); |
| | $newSlice = array_slice($newLines, $start, $n - $start - $end); |
| | + |
| | + $cntOld = count($oldSlice); |
| | + $cntNew = count($newSlice); |
| | + |
| | + if (($cntOld * $cntNew) > 500000) { |
| | + return [['t' => 'gap']]; |
| | + } |
| | |
| | $ops = $this->computeLCS($oldSlice, $newSlice); |
| | |
| | - // Grouping Optimization: Reorder interleaved +/- to be - then + |
| | $groupedOps = []; |
| | $bufferDel = []; |