]> source.dussan.org Git - jgit.git/commitdiff
Refactor NameConflictTreeWalk.fastMin method 70/194970/4
authorDmitrii Filippov <dmfilippov@google.com>
Mon, 1 Aug 2022 17:13:03 +0000 (19:13 +0200)
committerDmitrii Filippov <dmfilippov@google.com>
Mon, 1 Aug 2022 17:31:26 +0000 (13:31 -0400)
Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977

org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java

index 8085dfaa24ade630e655a31e4722a59874de99bc..2fd945b03f8454c13e5d6edf16b137a7c04e66ee 100644 (file)
@@ -118,15 +118,14 @@ public class NameConflictTreeWalk extends TreeWalk {
        }
 
        private AbstractTreeIterator fastMin() {
-               allTreesNamesMatchFastMinRef = true;
-
-               int i = 0;
+               int i = getFirstNonEofTreeIndex();
+               if (i == -1) {
+                       // All trees reached the end.
+                       allTreesNamesMatchFastMinRef = true;
+                       return trees[trees.length - 1];
+               }
                AbstractTreeIterator minRef = trees[i];
-               while (minRef.eof() && ++i < trees.length)
-                       minRef = trees[i];
-               if (minRef.eof())
-                       return minRef;
-
+               allTreesNamesMatchFastMinRef = true;
                boolean hasConflict = false;
                minRef.matches = minRef;
                while (++i < trees.length) {
@@ -180,6 +179,15 @@ public class NameConflictTreeWalk extends TreeWalk {
                return minRef;
        }
 
+       private int getFirstNonEofTreeIndex() {
+               for (int i = 0; i < trees.length; i++) {
+                       if (!trees[i].eof()) {
+                               return i;
+                       }
+               }
+               return -1;
+       }
+
        private static boolean nameEqual(final AbstractTreeIterator a,
                        final AbstractTreeIterator b) {
                return a.pathCompare(b, TREE_MODE) == 0;