check should be safe to move out of loop

This commit is contained in:
Xavier Léauté 2014-03-25 16:21:44 -07:00
parent 46a5409207
commit a0c38f574b
1 changed files with 11 additions and 15 deletions

View File

@ -350,7 +350,7 @@ public abstract class HyperLogLogCollector implements Comparable<HyperLogLogColl
byte myOffset = getRegisterOffset();
short numNonZero = getNumNonZeroRegisters();
int offsetDiff = myOffset - otherOffset;
final int offsetDiff = myOffset - otherOffset;
if (offsetDiff < 0) {
throw new ISE("offsetDiff[%d] < 0, shouldn't happen because of swap.", offsetDiff);
}
@ -368,13 +368,11 @@ public abstract class HyperLogLogCollector implements Comparable<HyperLogLogColl
offsetDiff,
otherBuffer.get()
);
if (numNonZero == NUM_BUCKETS) {
numNonZero = decrementBuckets();
setRegisterOffset(++myOffset);
setNumNonZeroRegisters(numNonZero);
offsetDiff = myOffset - otherOffset;
}
}
if (numNonZero == NUM_BUCKETS) {
numNonZero = decrementBuckets();
setRegisterOffset(++myOffset);
setNumNonZeroRegisters(numNonZero);
}
} else { // dense
int position = getPayloadBytePosition();
@ -384,15 +382,13 @@ public abstract class HyperLogLogCollector implements Comparable<HyperLogLogColl
offsetDiff,
otherBuffer.get()
);
if (numNonZero == NUM_BUCKETS) {
numNonZero = decrementBuckets();
setRegisterOffset(++myOffset);
setNumNonZeroRegisters(numNonZero);
offsetDiff = myOffset - otherOffset;
}
position++;
}
if (numNonZero == NUM_BUCKETS) {
numNonZero = decrementBuckets();
setRegisterOffset(++myOffset);
setNumNonZeroRegisters(numNonZero);
}
}
// no need to call setRegisterOffset(myOffset) here, since it gets updated every time myOffset is incremented