Source:
<code>private int replay() throws IOException { int fragments = 0; if (!publication.isConnected()) { state(State.INACTIVE); return fragments; } if (null != limitPosition && replayPosition >= stopPosition && noNewData(replayPosition, stopPosition)) { return fragments; } if (termOffset == termLength) { nextTerm(); } int frameOffset = 0; final int bytesRead = readRecording(stopPosition - replayPosition); while (frameOffset < bytesRead) { final int frameLength = frameLength(replayBuffer, frameOffset); if (frameLength <= 0) { throw new IllegalStateException("unexpected end of recording reached at position " + replayPosition); } final int frameType = frameType(replayBuffer, frameOffset); final int alignedLength = BitUtil.align(frameLength, FRAME_ALIGNMENT); final int dataLength = frameLength - DataHeaderFlyweight.HEADER_LENGTH; long result = 0; if (frameType == HeaderFlyweight.HDR_TYPE_DATA) { if (frameOffset + alignedLength > bytesRead) { break; } result = publication.tryClaim(dataLength, bufferClaim); if (result > 0) { if (crcEnabled) { <START> applyCrc(frameOffset, alignedLength); <END> } bufferClaim .flags(frameFlags(replayBuffer, frameOffset)) .reservedValue(replayBuffer.getLong(frameOffset + RESERVED_VALUE_OFFSET, LITTLE_ENDIAN)) .putBytes(replayBuffer, frameOffset + DataHeaderFlyweight.HEADER_LENGTH, dataLength) .commit(); } } else if (frameType == HeaderFlyweight.HDR_TYPE_PAD) { result = publication.appendPadding(dataLength); } if (result > 0) { fragments++; frameOffset += alignedLength; termOffset += alignedLength; replayPosition += alignedLength; if (replayPosition >= replayLimit) { state(State.INACTIVE); break; } } else { if (Publication.CLOSED == result || Publication.NOT_CONNECTED == result) { onError("stream closed before replay is complete"); } break; } } return fragments; }</code><technical_language>Apply claim window small reduce cache misses probability of buffer unblocking</technical_language>

Target:
private int replay() throws IOException { int fragments = 0; if (!publication.isConnected()) { state(State.INACTIVE); return fragments; } if (null != limitPosition && replayPosition >= stopPosition && noNewData(replayPosition, stopPosition)) { return fragments; } if (termOffset == termLength) { nextTerm(); } int frameOffset = 0; final int bytesRead = readRecording(stopPosition - replayPosition); while (frameOffset < bytesRead) { final int frameLength = frameLength(replayBuffer, frameOffset); if (frameLength <= 0) { throw new IllegalStateException("unexpected end of recording reached at position " + replayPosition); } final int frameType = frameType(replayBuffer, frameOffset); final int alignedLength = BitUtil.align(frameLength, FRAME_ALIGNMENT); final int dataLength = frameLength - DataHeaderFlyweight.HEADER_LENGTH; long result = 0; if (frameType == HeaderFlyweight.HDR_TYPE_DATA) { if (frameOffset + alignedLength > bytesRead) { break; } final Checksum checksum = this.checksum; if (null != checksum) { applyCrc(checksum, frameOffset, alignedLength); } result = publication.tryClaim(dataLength, bufferClaim); if (result > 0) { bufferClaim .flags(frameFlags(replayBuffer, frameOffset)) .reservedValue(replayBuffer.getLong(frameOffset + RESERVED_VALUE_OFFSET, LITTLE_ENDIAN)) .putBytes(replayBuffer, frameOffset + DataHeaderFlyweight.HEADER_LENGTH, dataLength) .commit(); } } else if (frameType == HeaderFlyweight.HDR_TYPE_PAD) { result = publication.appendPadding(dataLength); } if (result > 0) { fragments++; frameOffset += alignedLength; termOffset += alignedLength; replayPosition += alignedLength; if (replayPosition >= replayLimit) { state(State.INACTIVE); break; } } else { if (Publication.CLOSED == result || Publication.NOT_CONNECTED == result) { onError("stream closed before replay is complete"); } break; } } return fragments; }