Skip to content

Fix ByteBufferBsonOutput buffer caching logic. #1683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.ArrayList;
import java.util.List;

import static com.mongodb.assertions.Assertions.assertFalse;
import static com.mongodb.assertions.Assertions.assertTrue;
import static com.mongodb.assertions.Assertions.notNull;
import static java.lang.String.format;
Expand Down Expand Up @@ -176,6 +175,7 @@ private ByteBuf getCurrentByteBuffer() {
if (currentByteBuffer == null) {
currentByteBuffer = getByteBufferAtIndex(curBufferIndex);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[optional]

Was this change intentional or accidental? I ma pointing it out just in case it was an accident. If not, feel free to merge.

Copy link
Member Author

@vbabanin vbabanin Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change was intentional - i thought visually separating the branches (after the recent changes in #1675) might help make the logic a bit more apparent. Thank you for flagging it!

if (currentByteBuffer.hasRemaining()) {
return currentByteBuffer;
}
Expand All @@ -185,11 +185,6 @@ private ByteBuf getCurrentByteBuffer() {
return currentByteBuffer;
}

private ByteBuf getNextByteBuffer() {
assertFalse(bufferList.get(curBufferIndex).hasRemaining());
return getByteBufferAtIndex(++curBufferIndex);
}

private ByteBuf getByteBufferAtIndex(final int index) {
if (bufferList.size() < index + 1) {
ByteBuf buffer = bufferProvider.getBuffer(index >= (MAX_SHIFT - INITIAL_SHIFT)
Expand Down Expand Up @@ -459,7 +454,7 @@ private int writeOnBuffers(final String str,

if (c < 0x80) {
if (remaining == 0) {
curBuffer = getNextByteBuffer();
curBuffer = getCurrentByteBuffer();
curBufferPos = 0;
curBufferLimit = curBuffer.limit();
}
Expand Down