From b544da795bc242d76572384b46a8ae1141d040e0 Mon Sep 17 00:00:00 2001 From: Dmitrii Filippov Date: Mon, 1 Aug 2022 19:13:03 +0200 Subject: [PATCH] Refactor NameConflictTreeWalk.fastMin method Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977 --- .../jgit/treewalk/NameConflictTreeWalk.java | 24 ++++++++++++------- 1 file 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; -- 2.39.5