Skip to content

Commit

Permalink
Improve ByteBuffer copy method
Browse files Browse the repository at this point in the history
This commit improves JettyWebSocketHandlerAdapter::copyByteBuffer so
that it allocates a buffer large enough for the remaining bytes
contained in the source, instead of allocating one with the capacity of
the source.

Closes gh-31857
  • Loading branch information
poutsma committed Dec 18, 2023
1 parent eaf7a28 commit 24f8eac
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ public void onWebSocketFrame(Frame frame, Callback callback) {
}

private static ByteBuffer copyByteBuffer(ByteBuffer src) {
ByteBuffer dest = ByteBuffer.allocate(src.capacity());
dest.put(0, src, 0, src.remaining());
ByteBuffer dest = ByteBuffer.allocate(src.remaining());
dest.put(src);
dest.flip();
return dest;
}

Expand Down

0 comments on commit 24f8eac

Please sign in to comment.