aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitrii Filippov <dmfilippov@google.com>2022-08-01 19:13:03 +0200
committerDmitrii Filippov <dmfilippov@google.com>2022-08-01 13:31:26 -0400
commitb544da795bc242d76572384b46a8ae1141d040e0 (patch)
tree46629bc6f971ce62c247c03be3be062c863ce869
parent5af93628d4293048597affd343d951931594051d (diff)
downloadjgit-b544da795bc242d76572384b46a8ae1141d040e0.tar.gz
jgit-b544da795bc242d76572384b46a8ae1141d040e0.zip
Refactor NameConflictTreeWalk.fastMin method
Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java24
1 files changed, 16 insertions, 8 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
index 8085dfaa24..2fd945b03f 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
@@ -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;