protected $xchanged, $ychanged;
- protected $xv = array(), $yv = array();
- protected $xind = array(), $yind = array();
+ protected $xv = [], $yv = [];
+ protected $xind = [], $yind = [];
- protected $seq = array(), $in_seq = array();
+ protected $seq = [], $in_seq = [];
protected $lcs = 0;
$n_from = count( $from_lines );
$n_to = count( $to_lines );
- $edits = array();
+ $edits = [];
$xi = $yi = 0;
while ( $xi < $n_from || $yi < $n_to ) {
- assert( '$yi < $n_to || $this->xchanged[$xi]' );
- assert( '$xi < $n_from || $this->ychanged[$yi]' );
+ assert( $yi < $n_to || $this->xchanged[$xi] );
+ assert( $xi < $n_from || $this->ychanged[$yi] );
// Skip matching "snake".
- $copy = array();
+ $copy = [];
while ( $xi < $n_from && $yi < $n_to
&& !$this->xchanged[$xi] && !$this->ychanged[$yi]
) {
}
// Find deletes & adds.
- $delete = array();
+ $delete = [];
while ( $xi < $n_from && $this->xchanged[$xi] ) {
$delete[] = $from_lines[$xi++];
}
- $add = array();
+ $add = [];
while ( $yi < $n_to && $this->ychanged[$yi] ) {
$add[] = $to_lines[$yi++];
}
// old diff
$n_from = count( $from_lines );
$n_to = count( $to_lines );
- $this->xchanged = $this->ychanged = array();
- $this->xv = $this->yv = array();
- $this->xind = $this->yind = array();
- $this->seq = array();
- $this->in_seq = array();
+ $this->xchanged = $this->ychanged = [];
+ $this->xv = $this->yv = [];
+ $this->xind = $this->yind = [];
+ $this->seq = [];
+ $this->in_seq = [];
$this->lcs = 0;
// Skip leading common lines.
// Things seems faster (I'm not sure I understand why)
// when the shortest sequence in X.
$flip = true;
- list( $xoff, $xlim, $yoff, $ylim ) = array( $yoff, $ylim, $xoff, $xlim );
+ list( $xoff, $xlim, $yoff, $ylim ) = [ $yoff, $ylim, $xoff, $xlim ];
}
if ( $flip ) {
$this->lcs = 0;
$this->seq[0] = $yoff - 1;
- $this->in_seq = array();
- $ymids[0] = array();
+ $this->in_seq = [];
+ $ymids[0] = [];
$numer = $xlim - $xoff + $nchunks - 1;
$x = $xoff;
while ( list( , $y ) = each( $matches ) ) {
if ( empty( $this->in_seq[$y] ) ) {
$k = $this->lcsPos( $y );
- assert( '$k > 0' );
+ assert( $k > 0 );
$ymids[$k] = $ymids[$k - 1];
break;
}
while ( list( , $y ) = each( $matches ) ) {
if ( $y > $this->seq[$k - 1] ) {
- assert( '$y < $this->seq[$k]' );
+ assert( $y < $this->seq[$k] );
// Optimization: this is a common case:
// next match is just replacing previous match.
$this->in_seq[$this->seq[$k]] = false;
$this->in_seq[$y] = 1;
} elseif ( empty( $this->in_seq[$y] ) ) {
$k = $this->lcsPos( $y );
- assert( '$k > 0' );
+ assert( $k > 0 );
$ymids[$k] = $ymids[$k - 1];
}
}
}
}
- $seps[] = $flip ? array( $yoff, $xoff ) : array( $xoff, $yoff );
+ $seps[] = $flip ? [ $yoff, $xoff ] : [ $xoff, $yoff ];
$ymid = $ymids[$this->lcs];
for ( $n = 0; $n < $nchunks - 1; $n++ ) {
$x1 = $xoff + (int)( ( $numer + ( $xlim - $xoff ) * $n ) / $nchunks );
$y1 = $ymid[$n] + 1;
- $seps[] = $flip ? array( $y1, $x1 ) : array( $x1, $y1 );
+ $seps[] = $flip ? [ $y1, $x1 ] : [ $x1, $y1 ];
}
- $seps[] = $flip ? array( $ylim, $xlim ) : array( $xlim, $ylim );
+ $seps[] = $flip ? [ $ylim, $xlim ] : [ $xlim, $ylim ];
- return array( $this->lcs, $seps );
+ return [ $this->lcs, $seps ];
}
/**
}
}
- assert( '$ypos != $this->seq[$end]' );
+ assert( $ypos != $this->seq[$end] );
$this->in_seq[$this->seq[$end]] = false;
$this->seq[$end] = $ypos;
$i = 0;
$j = 0;
- assert( 'count($lines) == count($changed)' );
+ assert( count( $lines ) == count( $changed ) );
$len = count( $lines );
$other_len = count( $other_changed );
}
while ( $i < $len && !$changed[$i] ) {
- assert( '$j < $other_len && ! $other_changed[$j]' );
+ assert( $j < $other_len && ! $other_changed[$j] );
$i++;
$j++;
while ( $j < $other_len && $other_changed[$j] ) {
while ( $start > 0 && $changed[$start - 1] ) {
$start--;
}
- assert( '$j > 0' );
+ assert( $j > 0 );
while ( $other_changed[--$j] ) {
continue;
}
- assert( '$j >= 0 && !$other_changed[$j]' );
+ assert( $j >= 0 && !$other_changed[$j] );
}
/*
$i++;
}
- assert( '$j < $other_len && ! $other_changed[$j]' );
+ assert( $j < $other_len && ! $other_changed[$j] );
$j++;
if ( $j < $other_len && $other_changed[$j] ) {
$corresponding = $i;
while ( $corresponding < $i ) {
$changed[--$start] = 1;
$changed[--$i] = 0;
- assert( '$j > 0' );
+ assert( $j > 0 );
while ( $other_changed[--$j] ) {
continue;
}
- assert( '$j >= 0 && !$other_changed[$j]' );
+ assert( $j >= 0 && !$other_changed[$j] );
}
}
}
*/
public function reverse() {
$rev = $this;
- $rev->edits = array();
+ $rev->edits = [];
/** @var DiffOp $edit */
foreach ( $this->edits as $edit ) {
$rev->edits[] = $edit->reverse();
* @return string[] The original sequence of strings.
*/
public function orig() {
- $lines = array();
+ $lines = [];
foreach ( $this->edits as $edit ) {
if ( $edit->orig ) {
* @return string[] The sequence of strings.
*/
public function closing() {
- $lines = array();
+ $lines = [];
foreach ( $this->edits as $edit ) {
if ( $edit->closing ) {
public function __construct( $from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines ) {
- assert( 'count( $from_lines ) == count( $mapped_from_lines )' );
- assert( 'count( $to_lines ) == count( $mapped_to_lines )' );
+ assert( count( $from_lines ) == count( $mapped_from_lines ) );
+ assert( count( $to_lines ) == count( $mapped_to_lines ) );
parent::__construct( $mapped_from_lines, $mapped_to_lines );
public $insClass = ' class="diffchange diffchange-inline"';
public $delClass = ' class="diffchange diffchange-inline"';
- private $lines = array();
+ private $lines = [];
private $line = '';
private $group = '';
private $tag = '';
$this->flushLine( $tag );
$word = substr( $word, 1 );
}
- assert( '!strstr( $word, "\n" )' );
+ assert( !strstr( $word, "\n" ) );
$this->group .= $word;
}
}
*/
private function split( $lines ) {
- $words = array();
- $stripped = array();
+ $words = [];
+ $stripped = [];
$first = true;
foreach ( $lines as $line ) {
# If the line is too long, just pretend the entire line is one big word
$words[] = $line;
$stripped[] = $line;
} else {
- $m = array();
+ $m = [];
if ( preg_match_all( '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
$line, $m )
) {
}
}
- return array( $words, $stripped );
+ return [ $words, $stripped ];
}
/**