Skip to content

Commit

Permalink
Merge pull request #122 from jihoonson/skip-get-capacity
Browse files Browse the repository at this point in the history
Don't call getCapacity() in BaseState when asserting for read and write
  • Loading branch information
leerho committed Dec 1, 2020
2 parents 7d0278d + 1703161 commit ec00240
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/org/apache/datasketches/memory/BaseState.java
Expand Up @@ -371,12 +371,18 @@ final void checkValid() {

final void assertValidAndBoundsForRead(final long offsetBytes, final long lengthBytes) {
assertValid();
assertBounds(offsetBytes, lengthBytes, getCapacity());
// capacityBytes_ is intentionally read directly instead of calling getCapacity()
// because the later can make JVM to not inline the assert code path (and entirely remove it)
// even though it does nothing in production code path.
assertBounds(offsetBytes, lengthBytes, capacityBytes_);
}

final void assertValidAndBoundsForWrite(final long offsetBytes, final long lengthBytes) {
assertValid();
assertBounds(offsetBytes, lengthBytes, getCapacity());
// capacityBytes_ is intentionally read directly instead of calling getCapacity()
// because the later can make JVM to not inline the assert code path (and entirely remove it)
// even though it does nothing in production code path.
assertBounds(offsetBytes, lengthBytes, capacityBytes_);
assert !isReadOnly() : "Memory is read-only.";
}

Expand Down

0 comments on commit ec00240

Please sign in to comment.