summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2013-01-09 18:47:16 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-01-09 18:47:16 -0500
commitbc07097ebed072159375a98110553a2653d77353 (patch)
treec5ed9daa0e47079814560873821ef237f65941b7
parent576e5acdd054e2dcd8cde3fe4d822bc3609850c1 (diff)
downloadjgit-bc07097ebed072159375a98110553a2653d77353.tar.gz
jgit-bc07097ebed072159375a98110553a2653d77353.zip
Revert "Speed up PathFilterGroup.include for large set of paths"
This reverts commit 576e5acdd054e2dcd8cde3fe4d822bc3609850c1 The comparator is broken. Change-Id: Ic59110b154613f3ff4a215a6c1293a4c15cd3885
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java70
1 files changed, 15 insertions, 55 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java
index d4b0555cdb..51761a8126 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/filter/PathFilterGroup.java
@@ -177,73 +177,33 @@ public class PathFilterGroup {
}
static class Group extends TreeFilter {
- private static int pathPrefixSortCompare(byte[] p1, byte[] p2,
- boolean justMatch) {
- int ci = 0;
- while (ci < p1.length && ci < p2.length) {
- int c1 = p1[ci];
- int c2 = p2[ci];
- if (c1 == '/')
- c1 = 0;
- if (c2 == '/')
- c2 = 0;
- int cmp = c1 - c2;
- if (cmp != 0)
- return cmp;
- ++ci;
- }
- if (ci < p1.length) {
- int c1 = p1[ci];
- if (c1 == '/')
- if (justMatch)
- return 0;
- return 1;
- }
- if (ci < p2.length) {
- int c2 = p2[ci];
- if (c2 == '/')
- return 0;
- return -1;
- }
- return 0;
- }
-
- private static final Comparator<PathFilter> PATH_PREFIX_SORT = new Comparator<PathFilter>() {
+ private static final Comparator<PathFilter> PATH_SORT = new Comparator<PathFilter>() {
public int compare(final PathFilter o1, final PathFilter o2) {
- return pathPrefixSortCompare(o1.pathRaw, o2.pathRaw, false);
+ return o1.pathStr.compareTo(o2.pathStr);
}
-
};
private final PathFilter[] paths;
private Group(final PathFilter[] p) {
paths = p;
- Arrays.sort(paths, PATH_PREFIX_SORT);
+ Arrays.sort(paths, PATH_SORT);
}
@Override
public boolean include(final TreeWalk walker) {
- final byte[] rawPath = walker.getRawPath();
- Comparator comparator = new Comparator<Object>() {
- public int compare(Object pf, Object raw) {
- PathFilter pathFilter = (PathFilter) pf;
- int ret = -pathPrefixSortCompare(walker.getRawPath(),
- pathFilter.pathRaw, true);
- return ret;
- }
- };
-
- Object[] pathsObject = paths;
- Object rawObject = rawPath;
- @SuppressWarnings("unchecked")
- int position = Arrays.binarySearch(pathsObject, rawObject,
- comparator);
- if (position >= 0)
- return true;
- if (position == -paths.length - 1)
- throw StopWalkException.INSTANCE;
- return false;
+ final int n = paths.length;
+ for (int i = 0;;) {
+ final byte[] r = paths[i].pathRaw;
+ final int cmp = walker.isPathPrefix(r, r.length);
+ if (cmp == 0)
+ return true;
+ if (++i < n)
+ continue;
+ if (cmp > 0)
+ throw StopWalkException.INSTANCE;
+ return false;
+ }
}
@Override