Dave Jarvis' Repositories

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

Fixes duplicate method

Author Dave Jarvis <email>
Date 2026-02-18 17:41:01 GMT-0800
Commit c44fa7ffe009913b604579ed7e8c936ca8e9d6eb
Parent a30737e
git/GitDiff.php
}
- private function buildFallbackDiff(
- array $old,
- array $new,
- int $offset
- ): array {
- $stream = [];
- $currO = $offset + 1;
- $currN = $offset + 1;
-
- foreach( $old as $line ) {
- $stream[] = [ 't' => '-', 'l' => $line, 'no' => $currO++, 'nn' => null ];
- }
-
- foreach( $new as $line ) {
- $stream[] = [ 't' => '+', 'l' => $line, 'no' => null, 'nn' => $currN++ ];
- }
-
- return $stream;
- }
-
- private function buildDiffStream( array $ops, int $start ): array {
- $stream = [];
- $currO = $start + 1;
- $currN = $start + 1;
-
- foreach( $ops as $op ) {
- $stream[] = [
- 't' => $op['t'],
- 'l' => $op['l'],
- 'no' => $op['t'] === '+' ? null : $currO++,
- 'nn' => $op['t'] === '-' ? null : $currN++
- ];
- }
-
- return $stream;
- }
-
-private function calculateDiff( string $old, string $new ): array {
- $oldLines = explode( "\n", str_replace( "\r\n", "\n", $old ) );
- $newLines = explode( "\n", str_replace( "\r\n", "\n", $new ) );
- $m = count( $oldLines );
- $n = count( $newLines );
- $start = 0;
- $end = 0;
-
- while( $start < $m && $start < $n &&
- $oldLines[$start] === $newLines[$start] ) {
- $start++;
- }
-
- while( $m - $end > $start && $n - $end > $start &&
- $oldLines[$m - 1 - $end] === $newLines[$n - 1 - $end] ) {
- $end++;
- }
-
- $oldSlice = array_slice( $oldLines, $start, $m - $start - $end );
- $newSlice = array_slice( $newLines, $start, $n - $start - $end );
- $limit = 100000;
- $stream = [];
-
- for( $i = 0; $i < $start; $i++ ) {
- $stream[] = [
- 't' => ' ',
- 'l' => $oldLines[$i],
- 'no' => $i + 1,
- 'nn' => $i + 1
- ];
- }
-
- $mid = [];
-
- if( (count( $oldSlice ) * count( $newSlice )) > $limit ) {
- $mid = $this->buildFallbackDiff( $oldSlice, $newSlice, $start );
- } else {
- $ops = $this->computeLCS( $oldSlice, $newSlice );
- $mid = $this->buildDiffStream( $ops, $start );
- }
-
- foreach( $mid as $line ) {
- $stream[] = $line;
- }
-
- for( $i = 0; $i < $end; $i++ ) {
- $idxO = $m - $end + $i;
- $idxN = $n - $end + $i;
- $stream[] = [
- 't' => ' ',
- 'l' => $oldLines[$idxO],
- 'no' => $idxO + 1,
- 'nn' => $idxN + 1
- ];
- }
-
- return $this->formatDiffOutput( $stream );
- }
-
private function formatDiffOutput( array $stream ): array {
$n = count( $stream );
return $result;
+ }
+
+ private function buildFallbackDiff(
+ array $old,
+ array $new,
+ int $offset
+ ): array {
+ $stream = [];
+ $currO = $offset + 1;
+ $currN = $offset + 1;
+
+ foreach( $old as $line ) {
+ $stream[] = [
+ 't' => '-',
+ 'l' => $line,
+ 'no' => $currO++,
+ 'nn' => null
+ ];
+ }
+
+ foreach( $new as $line ) {
+ $stream[] = [
+ 't' => '+',
+ 'l' => $line,
+ 'no' => null,
+ 'nn' => $currN++
+ ];
+ }
+
+ return $stream;
+ }
+
+ private function buildDiffStream( array $ops, int $start ): array {
+ $stream = [];
+ $currO = $start + 1;
+ $currN = $start + 1;
+
+ foreach( $ops as $op ) {
+ $stream[] = [
+ 't' => $op['t'],
+ 'l' => $op['l'],
+ 'no' => $op['t'] === '+' ? null : $currO++,
+ 'nn' => $op['t'] === '-' ? null : $currN++
+ ];
+ }
+
+ return $stream;
}
Delta 47 lines added, 96 lines removed, 49-line decrease