Refactor difflib to not use each()

This commit is contained in:
Aaron Carlino 2018-05-31 12:38:41 +12:00
parent 8e4a1ba8fa
commit c8a1bb314d
1 changed files with 3 additions and 1 deletions

View File

@ -283,14 +283,16 @@ class DiffEngine
continue; continue;
$matches = $ymatches[$line]; $matches = $ymatches[$line];
reset($matches); reset($matches);
$pointer = 0;
foreach ($matches as $y) foreach ($matches as $y)
$pointer++;
if (empty($this->in_seq[$y])) { if (empty($this->in_seq[$y])) {
$k = $this->lcs_pos($y); $k = $this->lcs_pos($y);
assert($k > 0); assert($k > 0);
$ymids[$k] = $ymids[$k - 1]; $ymids[$k] = $ymids[$k - 1];
break; break;
} }
foreach ($matches as $y) { foreach (array_slice($matches, $pointer) as $y) {
if ($y > $this->seq[$k - 1]) { if ($y > $this->seq[$k - 1]) {
assert($y < $this->seq[$k]); assert($y < $this->seq[$k]);
// Optimization: this is a common case: // Optimization: this is a common case: