Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Component / Diff / Engine / DiffEngine.php
index b56aa99aa7ca43b438c4712b0a1b64ee5b273537..27b0f325724b09ba31deb109af71a2086c0db250 100644 (file)
@@ -201,28 +201,30 @@ class DiffEngine {
           continue;
         }
         $matches = $ymatches[$line];
-        reset($matches);
-        while (list ($junk, $y) = each($matches)) {
-          if (empty($this->in_seq[$y])) {
-            $k = $this->_lcs_pos($y);
-            $this::USE_ASSERTS && assert($k > 0);
-            $ymids[$k] = $ymids[$k - 1];
-            break;
-          }
-        }
-        while (list ($junk, $y) = each($matches)) {
-          if ($y > $this->seq[$k - 1]) {
-            $this::USE_ASSERTS && 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->seq[$k] = $y;
-            $this->in_seq[$y] = 1;
+        $found_empty = FALSE;
+        foreach ($matches as $y) {
+          if (!$found_empty) {
+            if (empty($this->in_seq[$y])) {
+              $k = $this->_lcs_pos($y);
+              $this::USE_ASSERTS && assert($k > 0);
+              $ymids[$k] = $ymids[$k - 1];
+              $found_empty = TRUE;
+            }
           }
-          elseif (empty($this->in_seq[$y])) {
-            $k = $this->_lcs_pos($y);
-            $this::USE_ASSERTS && assert($k > 0);
-            $ymids[$k] = $ymids[$k - 1];
+          else {
+            if ($y > $this->seq[$k - 1]) {
+              $this::USE_ASSERTS && 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->seq[$k] = $y;
+              $this->in_seq[$y] = 1;
+            }
+            elseif (empty($this->in_seq[$y])) {
+              $k = $this->_lcs_pos($y);
+              $this::USE_ASSERTS && assert($k > 0);
+              $ymids[$k] = $ymids[$k - 1];
+            }
           }
         }
       }
@@ -343,7 +345,7 @@ class DiffEngine {
     $i = 0;
     $j = 0;
 
-    $this::USE_ASSERTS && assert('sizeof($lines) == sizeof($changed)');
+    $this::USE_ASSERTS && assert(sizeof($lines) == sizeof($changed));
     $len = sizeof($lines);
     $other_len = sizeof($other_changed);
 
@@ -363,7 +365,7 @@ class DiffEngine {
         $j++;
       }
       while ($i < $len && !$changed[$i]) {
-        $this::USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
+        $this::USE_ASSERTS && assert($j < $other_len && ! $other_changed[$j]);
         $i++;
         $j++;
         while ($j < $other_len && $other_changed[$j]) {
@@ -399,11 +401,11 @@ class DiffEngine {
           while ($start > 0 && $changed[$start - 1]) {
             $start--;
           }
-          $this::USE_ASSERTS && assert('$j > 0');
+          $this::USE_ASSERTS && assert($j > 0);
           while ($other_changed[--$j]) {
             continue;
           }
-          $this::USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
+          $this::USE_ASSERTS && assert($j >= 0 && !$other_changed[$j]);
         }
 
         /*
@@ -426,7 +428,7 @@ class DiffEngine {
           while ($i < $len && $changed[$i]) {
             $i++;
           }
-          $this::USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
+          $this::USE_ASSERTS && assert($j < $other_len && ! $other_changed[$j]);
           $j++;
           if ($j < $other_len && $other_changed[$j]) {
             $corresponding = $i;
@@ -444,11 +446,11 @@ class DiffEngine {
       while ($corresponding < $i) {
         $changed[--$start] = 1;
         $changed[--$i] = 0;
-        $this::USE_ASSERTS && assert('$j > 0');
+        $this::USE_ASSERTS && assert($j > 0);
         while ($other_changed[--$j]) {
           continue;
         }
-        $this::USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
+        $this::USE_ASSERTS && assert($j >= 0 && !$other_changed[$j]);
       }
     }
   }