wp/wp-includes/Text/Diff/Engine/native.php
changeset 7 cf61fcea0001
parent 0 d970ebf37754
child 21 48c4eec2b7e6
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
   188                 if (empty($ymatches[$line])) {
   188                 if (empty($ymatches[$line])) {
   189                     continue;
   189                     continue;
   190                 }
   190                 }
   191                 $matches = $ymatches[$line];
   191                 $matches = $ymatches[$line];
   192                 reset($matches);
   192                 reset($matches);
   193                 while (list(, $y) = each($matches)) {
   193                 while ($y = current($matches)) {
   194                     if (empty($this->in_seq[$y])) {
   194                     if (empty($this->in_seq[$y])) {
   195                         $k = $this->_lcsPos($y);
   195                         $k = $this->_lcsPos($y);
   196                         assert($k > 0);
   196                         assert($k > 0);
   197                         $ymids[$k] = $ymids[$k - 1];
   197                         $ymids[$k] = $ymids[$k - 1];
   198                         break;
   198                         break;
   199                     }
   199                     }
   200                 }
   200                     next($matches);
   201                 while (list(, $y) = each($matches)) {
   201                 }
       
   202                 while ($y = current($matches)) {
   202                     if ($y > $this->seq[$k - 1]) {
   203                     if ($y > $this->seq[$k - 1]) {
   203                         assert($y <= $this->seq[$k]);
   204                         assert($y <= $this->seq[$k]);
   204                         /* Optimization: this is a common case: next match is
   205                         /* Optimization: this is a common case: next match is
   205                          * just replacing previous match. */
   206                          * just replacing previous match. */
   206                         $this->in_seq[$this->seq[$k]] = false;
   207                         $this->in_seq[$this->seq[$k]] = false;
   209                     } elseif (empty($this->in_seq[$y])) {
   210                     } elseif (empty($this->in_seq[$y])) {
   210                         $k = $this->_lcsPos($y);
   211                         $k = $this->_lcsPos($y);
   211                         assert($k > 0);
   212                         assert($k > 0);
   212                         $ymids[$k] = $ymids[$k - 1];
   213                         $ymids[$k] = $ymids[$k - 1];
   213                     }
   214                     }
       
   215                     next($matches);
   214                 }
   216                 }
   215             }
   217             }
   216         }
   218         }
   217 
   219 
   218         $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
   220         $seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
   328     function _shiftBoundaries($lines, &$changed, $other_changed)
   330     function _shiftBoundaries($lines, &$changed, $other_changed)
   329     {
   331     {
   330         $i = 0;
   332         $i = 0;
   331         $j = 0;
   333         $j = 0;
   332 
   334 
   333         assert('count($lines) == count($changed)');
   335         assert(count($lines) == count($changed));
   334         $len = count($lines);
   336         $len = count($lines);
   335         $other_len = count($other_changed);
   337         $other_len = count($other_changed);
   336 
   338 
   337         while (1) {
   339         while (1) {
   338             /* Scan forward to find the beginning of another run of
   340             /* Scan forward to find the beginning of another run of
   349             while ($j < $other_len && $other_changed[$j]) {
   351             while ($j < $other_len && $other_changed[$j]) {
   350                 $j++;
   352                 $j++;
   351             }
   353             }
   352 
   354 
   353             while ($i < $len && ! $changed[$i]) {
   355             while ($i < $len && ! $changed[$i]) {
   354                 assert('$j < $other_len && ! $other_changed[$j]');
   356                 assert($j < $other_len && ! $other_changed[$j]);
   355                 $i++; $j++;
   357                 $i++; $j++;
   356                 while ($j < $other_len && $other_changed[$j]) {
   358                 while ($j < $other_len && $other_changed[$j]) {
   357                     $j++;
   359                     $j++;
   358                 }
   360                 }
   359             }
   361             }
   381                     $changed[--$start] = 1;
   383                     $changed[--$start] = 1;
   382                     $changed[--$i] = false;
   384                     $changed[--$i] = false;
   383                     while ($start > 0 && $changed[$start - 1]) {
   385                     while ($start > 0 && $changed[$start - 1]) {
   384                         $start--;
   386                         $start--;
   385                     }
   387                     }
   386                     assert('$j > 0');
   388                     assert($j > 0);
   387                     while ($other_changed[--$j]) {
   389                     while ($other_changed[--$j]) {
   388                         continue;
   390                         continue;
   389                     }
   391                     }
   390                     assert('$j >= 0 && !$other_changed[$j]');
   392                     assert($j >= 0 && !$other_changed[$j]);
   391                 }
   393                 }
   392 
   394 
   393                 /* Set CORRESPONDING to the end of the changed run, at the
   395                 /* Set CORRESPONDING to the end of the changed run, at the
   394                  * last point where it corresponds to a changed run in the
   396                  * last point where it corresponds to a changed run in the
   395                  * other file. CORRESPONDING == LEN means no such point has
   397                  * other file. CORRESPONDING == LEN means no such point has
   406                     $changed[$i++] = 1;
   408                     $changed[$i++] = 1;
   407                     while ($i < $len && $changed[$i]) {
   409                     while ($i < $len && $changed[$i]) {
   408                         $i++;
   410                         $i++;
   409                     }
   411                     }
   410 
   412 
   411                     assert('$j < $other_len && ! $other_changed[$j]');
   413                     assert($j < $other_len && ! $other_changed[$j]);
   412                     $j++;
   414                     $j++;
   413                     if ($j < $other_len && $other_changed[$j]) {
   415                     if ($j < $other_len && $other_changed[$j]) {
   414                         $corresponding = $i;
   416                         $corresponding = $i;
   415                         while ($j < $other_len && $other_changed[$j]) {
   417                         while ($j < $other_len && $other_changed[$j]) {
   416                             $j++;
   418                             $j++;
   422             /* If possible, move the fully-merged run of changes back to a
   424             /* If possible, move the fully-merged run of changes back to a
   423              * corresponding run in the other file. */
   425              * corresponding run in the other file. */
   424             while ($corresponding < $i) {
   426             while ($corresponding < $i) {
   425                 $changed[--$start] = 1;
   427                 $changed[--$start] = 1;
   426                 $changed[--$i] = 0;
   428                 $changed[--$i] = 0;
   427                 assert('$j > 0');
   429                 assert($j > 0);
   428                 while ($other_changed[--$j]) {
   430                 while ($other_changed[--$j]) {
   429                     continue;
   431                     continue;
   430                 }
   432                 }
   431                 assert('$j >= 0 && !$other_changed[$j]');
   433                 assert($j >= 0 && !$other_changed[$j]);
   432             }
   434             }
   433         }
   435         }
   434     }
   436     }
   435 
   437 
   436 }
   438 }