From 14f72dd46eaf2f2293cbe79c93cc0bc43161a211 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Mon, 30 Nov 2020 08:59:04 +0100 Subject: [PATCH 1/6] Use >= operator instead of ^ operator for PHP version constraint --- ChangeLog.md | 7 +++++++ composer.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog.md b/ChangeLog.md index 76ccd877..88332f7d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [3.0.3] - 2020-11-30 + +### Changed + +* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1` + ## [3.0.2] - 2019-02-04 ### Changed @@ -46,6 +52,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * This component is no longer supported on PHP 5.6 +[3.0.3]: https://github.com/sebastianbergmann/diff/compare/3.0.2...3.0.3 [3.0.2]: https://github.com/sebastianbergmann/diff/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/sebastianbergmann/diff/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/sebastianbergmann/diff/compare/2.0...3.0.0 diff --git a/composer.json b/composer.json index 59520e99..fe2d77fe 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": "^7.1" + "php": ">=7.1" }, "require-dev": { "phpunit/phpunit": "^7.5 || ^8.0", From 22fb2d42f4ede152b7705a157af4a422a6721e78 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 7 May 2023 07:27:46 +0200 Subject: [PATCH 2/6] Backport 792812ddc157fa153b24e62e731786bf82192d1c --- src/MemoryEfficientLongestCommonSubsequenceCalculator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MemoryEfficientLongestCommonSubsequenceCalculator.php b/src/MemoryEfficientLongestCommonSubsequenceCalculator.php index 82dc20c8..68670ddd 100644 --- a/src/MemoryEfficientLongestCommonSubsequenceCalculator.php +++ b/src/MemoryEfficientLongestCommonSubsequenceCalculator.php @@ -71,7 +71,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]; + } } } } From 78a9dc0ecd5beece47779566a9035082a7f9aac2 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 7 May 2023 07:28:44 +0200 Subject: [PATCH 3/6] Backport b0a1aadeaa7e20988bfa01a1a2467b958ae7231e --- ...ientLongestCommonSubsequenceCalculator.php | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/TimeEfficientLongestCommonSubsequenceCalculator.php b/src/TimeEfficientLongestCommonSubsequenceCalculator.php index 97dadbd5..690b46fe 100644 --- a/src/TimeEfficientLongestCommonSubsequenceCalculator.php +++ b/src/TimeEfficientLongestCommonSubsequenceCalculator.php @@ -33,12 +33,24 @@ public function calculate(array $from, array $to): array for ($i = 1; $i <= $fromLength; ++$i) { for ($j = 1; $j <= $toLength; ++$j) { - $o = ($j * $width) + $i; - $matrix[$o] = \max( - $matrix[$o - 1], - $matrix[$o - $width], - $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0 - ); + $o = ($j * $width) + $i; + + // don't use max() to avoid function call overhead + $firstOrLast = $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0; + + if ($matrix[$o - 1] > $matrix[$o - $width]) { + if ($firstOrLast > $matrix[$o - 1]) { + $matrix[$o] = $firstOrLast; + } else { + $matrix[$o] = $matrix[$o - 1]; + } + } else { + if ($firstOrLast > $matrix[$o - $width]) { + $matrix[$o] = $firstOrLast; + } else { + $matrix[$o] = $matrix[$o - $width]; + } + } } } From 6296a0c086dd0117c1b78b059374d7fcbe7545ae Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sun, 7 May 2023 07:30:20 +0200 Subject: [PATCH 4/6] Prepare release --- ChangeLog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 88332f7d..42804e6e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,13 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [3.0.4] - 2023-05-07 + +### Changed + +* [#118](https://github.com/sebastianbergmann/diff/pull/118): Improve performance of `MemoryEfficientLongestCommonSubsequenceCalculator` +* [#119](https://github.com/sebastianbergmann/diff/pull/119): Improve performance of `TimeEfficientLongestCommonSubsequenceCalculator` + ## [3.0.3] - 2020-11-30 ### Changed @@ -52,6 +59,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * This component is no longer supported on PHP 5.6 +[3.0.4]: https://github.com/sebastianbergmann/diff/compare/3.0.3...3.0.4 [3.0.3]: https://github.com/sebastianbergmann/diff/compare/3.0.2...3.0.3 [3.0.2]: https://github.com/sebastianbergmann/diff/compare/3.0.1...3.0.2 [3.0.1]: https://github.com/sebastianbergmann/diff/compare/3.0.0...3.0.1 From 19c13267f01acca90aff30f1233cad20dbd9b2e9 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 1 Mar 2024 14:47:55 +0100 Subject: [PATCH 5/6] Do not export non-essential files and prepare release --- .gitattributes | 10 ++++++++++ ChangeLog.md | 5 +++++ 2 files changed, 15 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..2d2f5a38 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +/.gitattributes export-ignore +/.gitignore export-ignore +/.github export-ignore +/.php_cs.dist export-ignore +/.travis.yml export-ignore +/build.xml export-ignore +/phpunit.xml export-ignore +/tests export-ignore + +*.php diff=php diff --git a/ChangeLog.md b/ChangeLog.md index 42804e6e..e6b86315 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,10 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [3.0.5] - 2023-03-01 + +* No code changes, only updated `.gitattributes` to not export non-essential files. + ## [3.0.4] - 2023-05-07 ### Changed @@ -59,6 +63,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * This component is no longer supported on PHP 5.6 +[3.0.5]: https://github.com/sebastianbergmann/diff/compare/3.0.4...3.0.5 [3.0.4]: https://github.com/sebastianbergmann/diff/compare/3.0.3...3.0.4 [3.0.3]: https://github.com/sebastianbergmann/diff/compare/3.0.2...3.0.3 [3.0.2]: https://github.com/sebastianbergmann/diff/compare/3.0.1...3.0.2 From 98ff311ca519c3aa73ccd3de053bdb377171d7b6 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 2 Mar 2024 07:16:36 +0100 Subject: [PATCH 6/6] Do not use implicitly nullable parameters and prepare release --- ChangeLog.md | 7 +++++++ src/Differ.php | 4 ++-- src/Exception/ConfigurationException.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index e6b86315..d14aaddf 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [3.0.6] - 2023-03-02 + +### Changed + +* Do not use implicitly nullable parameters + ## [3.0.5] - 2023-03-01 * No code changes, only updated `.gitattributes` to not export non-essential files. @@ -63,6 +69,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * This component is no longer supported on PHP 5.6 +[3.0.6]: https://github.com/sebastianbergmann/diff/compare/3.0.5...3.0.6 [3.0.5]: https://github.com/sebastianbergmann/diff/compare/3.0.4...3.0.5 [3.0.4]: https://github.com/sebastianbergmann/diff/compare/3.0.3...3.0.4 [3.0.3]: https://github.com/sebastianbergmann/diff/compare/3.0.2...3.0.3 diff --git a/src/Differ.php b/src/Differ.php index 3c90a5a1..74e31449 100644 --- a/src/Differ.php +++ b/src/Differ.php @@ -64,7 +64,7 @@ public function __construct($outputBuilder = null) * * @return string */ - public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null): string + public function diff($from, $to, ?LongestCommonSubsequenceCalculator $lcs = null): string { $diff = $this->diffToArray( $this->normalizeDiffInput($from), @@ -92,7 +92,7 @@ public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null) * * @return array */ - public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null): array + public function diffToArray($from, $to, ?LongestCommonSubsequenceCalculator $lcs = null): array { if (\is_string($from)) { $from = $this->splitStringByLines($from); diff --git a/src/Exception/ConfigurationException.php b/src/Exception/ConfigurationException.php index 78f16fde..f57ec950 100644 --- a/src/Exception/ConfigurationException.php +++ b/src/Exception/ConfigurationException.php @@ -24,7 +24,7 @@ public function __construct( string $expected, $value, int $code = 0, - \Exception $previous = null + ?\Exception $previous = null ) { parent::__construct( \sprintf(