Skip to content

Commit

Permalink
Avoid large allocations of tmp buffers in buferutil
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Tselovalnikov <[email protected]>
  • Loading branch information
SerCeMan committed Jul 15, 2020
1 parent 6d88f96 commit 1554768
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,12 @@ public static void writeTo(ByteBuffer buffer, OutputStream out) throws IOExcepti
}
else
{
byte[] bytes = new byte[TEMP_BUFFER_SIZE];
byte[] bytes = null;
while (buffer.hasRemaining())
{
int byteCountToWrite = Math.min(buffer.remaining(), TEMP_BUFFER_SIZE);
if (bytes == null)
bytes = new byte[byteCountToWrite];
buffer.get(bytes, 0, byteCountToWrite);
out.write(bytes, 0, byteCountToWrite);
}
Expand Down

0 comments on commit 1554768

Please sign in to comment.