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
This commit is contained in:
parent
c2d1183e39
commit
549034500a
|
@ -46,6 +46,7 @@
|
|||
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 RevCommit call() throws GitAPIException, NoHeadException,
|
|||
ConcurrentRefUpdateException,
|
||||
WrongRepositoryStateException {
|
||||
checkCallable();
|
||||
Collections.sort(only);
|
||||
|
||||
RepositoryState state = repo.getRepositoryState();
|
||||
if (!state.canCommit())
|
||||
|
@ -452,18 +454,15 @@ private DirCache createTemporaryIndex(ObjectId headId, DirCache index)
|
|||
* @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…
Reference in New Issue