diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2012-12-31 19:17:19 +0100 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2013-01-07 01:08:01 +0100 |
commit | 549034500a55ffc8f401fd73a74d8dc55f096d2f (patch) | |
tree | c5ed9daa0e47079814560873821ef237f65941b7 | |
parent | c2d1183e39174336605509642b6f60157b9e2c3a (diff) | |
download | jgit-549034500a55ffc8f401fd73a74d8dc55f096d2f.tar.gz jgit-549034500a55ffc8f401fd73a74d8dc55f096d2f.zip |
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
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java index f51b301cd5..056b47d0fd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java +++ b/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; } |