Skip to content

Commit 22fb2d4

Browse files
Backport 792812d
1 parent 14f72dd commit 22fb2d4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/MemoryEfficientLongestCommonSubsequenceCalculator.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ private function length(array $from, array $to): array
7171
if ($from[$i] === $to[$j]) {
7272
$current[$j + 1] = $prev[$j] + 1;
7373
} else {
74-
$current[$j + 1] = \max($current[$j], $prev[$j + 1]);
74+
// don't use max() to avoid function call overhead
75+
if ($current[$j] > $prev[$j + 1]) {
76+
$current[$j + 1] = $current[$j];
77+
} else {
78+
$current[$j + 1] = $prev[$j + 1];
79+
}
7580
}
7681
}
7782
}

0 commit comments

Comments
 (0)