Browse Source

Merge "[style] Add braces to DeltaTask"

stable-4.2
Jonathan Nieder 9 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
938ffa9503
  1. 44
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaTask.java

44
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/pack/DeltaTask.java

@ -110,10 +110,12 @@ final class DeltaTask implements Callable<Object> {
maxWork = s.size(); maxWork = s.size();
} }
} }
if (maxTask == null) if (maxTask == null) {
return null; return null;
if (maxTask.tryStealWork(maxSlice)) }
if (maxTask.tryStealWork(maxSlice)) {
return forThread.initWindow(maxSlice); return forThread.initWindow(maxSlice);
}
} }
} }
@ -138,26 +140,30 @@ final class DeltaTask implements Callable<Object> {
for (; w < weightPerThread && i < endIndex;) { for (; w < weightPerThread && i < endIndex;) {
if (nextTop < topPaths.size() if (nextTop < topPaths.size()
&& i == topPaths.get(nextTop).slice.beginIndex) { && i == topPaths.get(nextTop).slice.beginIndex) {
if (s < i) if (s < i) {
task.add(new Slice(s, i)); task.add(new Slice(s, i));
}
s = i = topPaths.get(nextTop++).slice.endIndex; s = i = topPaths.get(nextTop++).slice.endIndex;
} else } else {
w += list[i++].getWeight(); w += list[i++].getWeight();
}
} }
// Round up the slice to the end of a path. // Round up the slice to the end of a path.
if (s < i) { if (s < i) {
int h = list[i - 1].getPathHash(); int h = list[i - 1].getPathHash();
while (i < endIndex) { while (i < endIndex) {
if (h == list[i].getPathHash()) if (h == list[i].getPathHash()) {
i++; i++;
else } else {
break; break;
}
} }
task.add(new Slice(s, i)); task.add(new Slice(s, i));
} }
if (!task.slices.isEmpty()) if (!task.slices.isEmpty()) {
tasks.add(task); tasks.add(task);
}
} }
while (topPathItr.hasNext()) { while (topPathItr.hasNext()) {
WeightedPath p = topPathItr.next(); WeightedPath p = topPathItr.next();
@ -184,22 +190,25 @@ final class DeltaTask implements Callable<Object> {
if (topPaths.size() < threads) { if (topPaths.size() < threads) {
Slice s = new Slice(cp, i); Slice s = new Slice(cp, i);
topPaths.add(new WeightedPath(cw, s)); topPaths.add(new WeightedPath(cw, s));
if (topPaths.size() == threads) if (topPaths.size() == threads) {
Collections.sort(topPaths); Collections.sort(topPaths);
}
} else if (topPaths.get(0).weight < cw) { } else if (topPaths.get(0).weight < cw) {
Slice s = new Slice(cp, i); Slice s = new Slice(cp, i);
WeightedPath p = new WeightedPath(cw, s); WeightedPath p = new WeightedPath(cw, s);
topPaths.set(0, p); topPaths.set(0, p);
if (p.compareTo(topPaths.get(1)) > 0) if (p.compareTo(topPaths.get(1)) > 0) {
Collections.sort(topPaths); Collections.sort(topPaths);
}
} }
} }
cp = i; cp = i;
ch = o.getPathHash(); ch = o.getPathHash();
cw = 0; cw = 0;
} }
if (o.isEdge() || o.doNotAttemptDelta()) if (o.isEdge() || o.doNotAttemptDelta()) {
continue; continue;
}
cw += o.getWeight(); cw += o.getWeight();
totalWeight += o.getWeight(); totalWeight += o.getWeight();
} }
@ -212,8 +221,9 @@ final class DeltaTask implements Callable<Object> {
}); });
bytesPerUnit = 1; bytesPerUnit = 1;
while (MAX_METER <= (totalWeight / bytesPerUnit)) while (MAX_METER <= (totalWeight / bytesPerUnit)) {
bytesPerUnit <<= 10; bytesPerUnit <<= 10;
}
return topPaths; return topPaths;
} }
} }
@ -229,8 +239,9 @@ final class DeltaTask implements Callable<Object> {
public int compareTo(WeightedPath o) { public int compareTo(WeightedPath o) {
int cmp = Long.signum(weight - o.weight); int cmp = Long.signum(weight - o.weight);
if (cmp != 0) if (cmp != 0) {
return cmp; return cmp;
}
return slice.beginIndex - o.slice.beginIndex; return slice.beginIndex - o.slice.beginIndex;
} }
} }
@ -278,14 +289,16 @@ final class DeltaTask implements Callable<Object> {
DeltaWindow w; DeltaWindow w;
for (;;) { for (;;) {
synchronized (this) { synchronized (this) {
if (slices.isEmpty()) if (slices.isEmpty()) {
break; break;
}
w = initWindow(slices.removeFirst()); w = initWindow(slices.removeFirst());
} }
runWindow(w); runWindow(w);
} }
while ((w = block.stealWork(this)) != null) while ((w = block.stealWork(this)) != null) {
runWindow(w); runWindow(w);
}
} finally { } finally {
block.pm.endWorker(); block.pm.endWorker();
or.close(); or.close();
@ -315,8 +328,9 @@ final class DeltaTask implements Callable<Object> {
} }
synchronized Slice remaining() { synchronized Slice remaining() {
if (!slices.isEmpty()) if (!slices.isEmpty()) {
return slices.getLast(); return slices.getLast();
}
DeltaWindow d = dw; DeltaWindow d = dw;
return d != null ? d.remaining() : null; return d != null ? d.remaining() : null;
} }

Loading…
Cancel
Save