From: Dmitrii Filippov Date: Mon, 1 Aug 2022 17:13:03 +0000 (+0200) Subject: Refactor NameConflictTreeWalk.fastMin method X-Git-Tag: v6.3.0.202208161710-m3~17 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F194970%2F4;p=jgit.git Refactor NameConflictTreeWalk.fastMin method Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977 --- 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;