Skip to content

Commit

Permalink
Removed unnecessary closing of Iterable
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 17d63d9 commit 7be8afa
Showing 1 changed file with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,17 @@ public static Iterator<ChangePackageEnvelope> splitChangePackage(final AbstractC

private void init() {
int leafSizeCounter = 0;
// it is not necessary to close the operations iterable, because the iterator already does this
// in hasNext() if there are no more operations
final ESCloseableIterable<AbstractOperation> operations = changePackage.operations();
try {
for (final AbstractOperation operation : operations.iterable()) {
final int countLeafOperations = countLeafOperations(operation);
leafSizeCounter += countLeafOperations;
if (leafSizeCounter < changePackageFragmentSize) {
continue;
}
leafSizeCounter = 0;
count += 1;
for (final AbstractOperation operation : operations.iterable()) {
final int countLeafOperations = countLeafOperations(operation);
leafSizeCounter += countLeafOperations;
if (leafSizeCounter < changePackageFragmentSize) {
continue;
}
} finally {
operations.close();
leafSizeCounter = 0;
count += 1;
}
if (leafSizeCounter != 0 || count == 0) {
count += 1;
Expand All @@ -118,20 +116,15 @@ public boolean hasNext() {
envelope.setFragmentCount(count);
}

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

final AbstractOperation op = operationsIterator.next();
envelope.getFragment().add(ModelUtil.clone(op));
}

envelope.setFragmentIndex(fragmentIndex);

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

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

0 comments on commit 7be8afa

Please sign in to comment.