Refactor NameConflictTreeWalk.fastMin method

Change-Id: Iac2e6f615463e18ddf788e6ddfe15ef023cac977
This commit is contained in:
Dmitrii Filippov 2022-08-01 19:13:03 +02:00
parent 5af93628d4
commit b544da795b
1 changed files with 16 additions and 8 deletions

View File

@ -118,15 +118,14 @@ AbstractTreeIterator min() throws CorruptObjectException {
}
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 @@ && nameEqual(minRef, t)) {
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;