Skip to content

Commit

Permalink
create fragments more efficiently
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Barchfeld <markus.barchfeld@gmx.de>
  • Loading branch information
Markus Barchfeld committed Jul 20, 2016
1 parent f95e96a commit 108b4de
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public static Iterator<ChangePackageEnvelope> splitChangePackage(final AbstractC
return new Iterator<ChangePackageEnvelope>() {

private int fragmentIndex;
private int currentOpIndex;
private int count;
private boolean isInitialized;
private ChangePackageEnvelope envelope;
private Iterator<AbstractOperation> operationsIterator;
private ESCloseableIterable<AbstractOperation> operationsIterable;

private void init() {
int leafSizeCounter = 0;
Expand All @@ -101,12 +101,13 @@ private void init() {
if (leafSizeCounter != 0 || count == 0) {
count += 1;
}
isInitialized = true;
operationsIterable = changePackage.operations();
operationsIterator = operationsIterable.iterable().iterator();
}

public boolean hasNext() {

if (!isInitialized) {
if (operationsIterable == null) {
init();
}

Expand All @@ -117,17 +118,20 @@ public boolean hasNext() {
envelope.setFragmentCount(count);
}

boolean iteratorHasNext = false;
while (countLeafOperations(envelope.getFragment()) < changePackageFragmentSize
&& currentOpIndex < changePackage.size()) {
&& (iteratorHasNext = operationsIterator.hasNext())) {

// FIXME: get(opIndex) might be slow
final AbstractOperation op = changePackage.get(currentOpIndex);
final AbstractOperation op = operationsIterator.next();
envelope.getFragment().add(ModelUtil.clone(op));
currentOpIndex += 1;
}

envelope.setFragmentIndex(fragmentIndex);

if (!iteratorHasNext) {
operationsIterable.close();
}

if (!envelope.getFragment().isEmpty() || fragmentIndex == 0) {
return true;
}
Expand Down

0 comments on commit 108b4de

Please sign in to comment.