Skip to content

Commit 5792d35

Browse files
committed
Fix ByteBufferBsonOutput buffer caching logic.
1 parent 7fc074f commit 5792d35

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

driver-core/src/main/com/mongodb/internal/connection/ByteBufferBsonOutput.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ private ByteBuf getCurrentByteBuffer() {
176176
if (currentByteBuffer == null) {
177177
currentByteBuffer = getByteBufferAtIndex(curBufferIndex);
178178
}
179+
179180
if (currentByteBuffer.hasRemaining()) {
180181
return currentByteBuffer;
181182
}
@@ -185,11 +186,6 @@ private ByteBuf getCurrentByteBuffer() {
185186
return currentByteBuffer;
186187
}
187188

188-
private ByteBuf getNextByteBuffer() {
189-
assertFalse(bufferList.get(curBufferIndex).hasRemaining());
190-
return getByteBufferAtIndex(++curBufferIndex);
191-
}
192-
193189
private ByteBuf getByteBufferAtIndex(final int index) {
194190
if (bufferList.size() < index + 1) {
195191
ByteBuf buffer = bufferProvider.getBuffer(index >= (MAX_SHIFT - INITIAL_SHIFT)
@@ -459,7 +455,7 @@ private int writeOnBuffers(final String str,
459455

460456
if (c < 0x80) {
461457
if (remaining == 0) {
462-
curBuffer = getNextByteBuffer();
458+
curBuffer = getCurrentByteBuffer();
463459
curBufferPos = 0;
464460
curBufferLimit = curBuffer.limit();
465461
}

0 commit comments

Comments
 (0)