Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Fixes memory exhaustion

AuthorDave Jarvis <email>
Date2026-02-10 00:13:13 GMT-0800
Commit021d1afa9ed761368e6fb558b565243fc4bd6beb
Parenta1a7998
GitDiff.php
$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 = [];
Delta8 lines added, 2 lines removed, 6-line increase