Skip to content

Commit

Permalink
Backport 792812d
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed May 7, 2023
1 parent 3461e3f commit 0806e02
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/MemoryEfficientLongestCommonSubsequenceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ private function length(array $from, array $to): array
if ($from[$i] === $to[$j]) {
$current[$j + 1] = $prev[$j] + 1;
} else {
$current[$j + 1] = max($current[$j], $prev[$j + 1]);
// don't use max() to avoid function call overhead
if ($current[$j] > $prev[$j + 1]) {
$current[$j + 1] = $current[$j];
} else {
$current[$j + 1] = $prev[$j + 1];
}
}
}
}
Expand Down

0 comments on commit 0806e02

Please sign in to comment.