Skip to content
Merged
Show file tree
Hide file tree
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 @@ -25,8 +25,8 @@

/**
* This is a {@link BytesReference} backed by a {@link ByteBuffer}. The byte buffer can either be a heap or
* direct byte buffer. The reference is composed of the space between the {@link ByteBuffer#position} and
* {@link ByteBuffer#limit} at construction time. If the position or limit of the underlying byte buffer is
* direct byte buffer. The reference is composed of the space between the {@link ByteBuffer#position()} and
* {@link ByteBuffer#limit()} at construction time. If the position or limit of the underlying byte buffer is
* changed, those changes will not be reflected in this reference. However, modifying the limit or position
* of the underlying byte buffer is not recommended as those can be used during {@link ByteBuffer#get()}
* bounds checks. Use {@link ByteBuffer#duplicate()} at creation time if you plan on modifying the markers of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,24 @@ public static ByteBuffer[] toByteBuffers(BytesReference reference) {
* Returns BytesReference composed of the provided ByteBuffers.
*/
public static BytesReference fromByteBuffers(ByteBuffer[] buffers) {
ByteBufferReference[] references = new ByteBufferReference[buffers.length];
for (int i = 0; i < references.length; ++i) {
references[i] = new ByteBufferReference(buffers[i]);
}
int bufferCount = buffers.length;
if (bufferCount == 0) {
return BytesArray.EMPTY;
} else if (bufferCount == 1) {
return new ByteBufferReference(buffers[0]);
} else {
ByteBufferReference[] references = new ByteBufferReference[bufferCount];
for (int i = 0; i < bufferCount; ++i) {
references[i] = new ByteBufferReference(buffers[i]);
}

return new CompositeBytesReference(references);
return new CompositeBytesReference(references);
}
}

@Override
public int compareTo(final BytesReference other) {
return compareIterators(this, other, (a, b) -> a.compareTo(b));
return compareIterators(this, other, BytesRef::compareTo);
}

/**
Expand Down