Browse Source

Speed up handling of "only" paths in the CommitCommand

Use binary search to reduce the number of lookups for very large number
of paths.

Change-Id: I76a16594b756bffd95298897414485a9cd637819
stable-2.3
Robin Rosenberg 12 years ago
parent
commit
549034500a
  1. 23
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

23
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -46,6 +46,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -147,6 +148,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
ConcurrentRefUpdateException,
WrongRepositoryStateException {
checkCallable();
Collections.sort(only);
RepositoryState state = repo.getRepositoryState();
if (!state.canCommit())
@ -452,18 +454,15 @@ public class CommitCommand extends GitCommand<RevCommit> {
* @return the item's index in <code>only</code>; -1 if no item matches
*/
private int lookupOnly(String pathString) {
int i = 0;
for (String o : only) {
String p = pathString;
while (true) {
if (p.equals(o))
return i;
int l = p.lastIndexOf("/"); //$NON-NLS-1$
if (l < 1)
break;
p = p.substring(0, l);
}
i++;
String p = pathString;
while (true) {
int position = Collections.binarySearch(only, p);
if (position >= 0)
return position;
int l = p.lastIndexOf("/"); //$NON-NLS-1$
if (l < 1)
break;
p = p.substring(0, l);
}
return -1;
}

Loading…
Cancel
Save