From: Kevin Israel Date: Fri, 9 Oct 2015 19:48:50 +0000 (-0400) Subject: TableDiffFormatter: Don't repeatedly call array_shift() X-Git-Tag: 1.31.0-rc.0~7219^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=073eb68ca9c0f59720a3088d4f13478449c3315a;p=lhc%2Fweb%2Fwiklou.git TableDiffFormatter: Don't repeatedly call array_shift() This also fixes a bug that could cause deleted lines to appear as if they were replaced with blank lines rather than removed entirely. Change-Id: I99dc2862b130c02aed311f93236eb6b2dc50a0fb --- diff --git a/includes/diff/TableDiffFormatter.php b/includes/diff/TableDiffFormatter.php index f1826edc5e..bcae7467f7 100644 --- a/includes/diff/TableDiffFormatter.php +++ b/includes/diff/TableDiffFormatter.php @@ -204,16 +204,13 @@ class TableDiffFormatter extends DiffFormatter { # Notice that WordLevelDiff returns HTML-escaped output. # Hence, we will be calling addedLine/deletedLine without HTML-escaping. - $line = array_shift( $del ); - while ( $line ) { - $aline = array_shift( $add ); - $this->writeOutput( '' . $this->deletedLine( $line ) . - $this->addedLine( $aline ) . "\n" ); - $line = array_shift( $del ); - } - foreach ( $add as $line ) { # If any leftovers - $this->writeOutput( '' . $this->emptyLine() . - $this->addedLine( $line ) . "\n" ); + $ndel = count( $del ); + $nadd = count( $add ); + $n = max( $ndel, $nadd ); + for ( $i = 0; $i < $n; $i++ ) { + $delLine = $i < $ndel ? $this->deletedLine( $del[$i] ) : $this->emptyLine(); + $addLine = $i < $nadd ? $this->addedLine( $add[$i] ) : $this->emptyLine(); + $this->writeOutput( "{$delLine}{$addLine}\n" ); } }