Set max capacity for remaining buf

This allows the returned buffer to be a cached empty buf if the original buffer was already fully read
This commit is contained in:
Nassim Jahnke 2024-11-27 11:32:03 +01:00
parent d3f92ce9b8
commit 2f08f0d58c
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F

View File

@ -373,7 +373,7 @@ public class UserConnectionImpl implements UserConnection {
// Instead of allocating a possible unnecessarily large buffer to write the wrapper contents to, // Instead of allocating a possible unnecessarily large buffer to write the wrapper contents to,
// only allocate the remaining bytes and write the rest to the original buf's head directly. // only allocate the remaining bytes and write the rest to the original buf's head directly.
final ByteBuf remainingBuf = buf.alloc().buffer(remainingBytes); final ByteBuf remainingBuf = buf.alloc().buffer(remainingBytes, remainingBytes);
try { try {
// Copy before modifying the buffer // Copy before modifying the buffer
remainingBuf.writeBytes(buf, remainingBytes); remainingBuf.writeBytes(buf, remainingBytes);