WalkSorter: Short-circuit sorting a single element

Change-Id: I00646c54df3dcdc057b620011e9f2de2fd1adfd9
This commit is contained in:
Dave Borowitz
2015-06-04 12:17:10 -07:00
parent 4512829c41
commit c6132e6b81
2 changed files with 14 additions and 0 deletions

View File

@@ -131,6 +131,8 @@ class WalkSorter {
Multimap<RevCommit, PatchSetData> byCommit = byCommit(rw, in);
if (byCommit.isEmpty()) {
return ImmutableList.of();
} else if (byCommit.size() == 1) {
return ImmutableList.of(byCommit.values().iterator().next());
}
// Walk from all patch set SHA-1s, and terminate as soon as we've found

View File

@@ -219,6 +219,18 @@ public class WalkSorterTest {
assertThat(actual.getRawBuffer()).isNull();
}
@Test
public void oneChange() throws Exception {
TestRepository<Repo> p = newRepo("p");
RevCommit c = p.commit().create();
ChangeData cd = newChange(p, c);
List<ChangeData> changes = ImmutableList.of(cd);
WalkSorter sorter = new WalkSorter(repoManager);
assertSorted(sorter, changes, ImmutableList.of(patchSetData(cd, c)));
}
private ChangeData newChange(TestRepository<Repo> tr, ObjectId id)
throws Exception {
Project.NameKey project = tr.getRepository().getDescription().getProject();