Skip to content

Commit

Permalink
Fix issue jetty#5499
Browse files Browse the repository at this point in the history
this PR let the ByteAccumulator recyclable. after invoke ByteAccumulator.transferTo method
we can invoke ByteAccumulator.recycle method to reuse byte[] via ByteAccumulator.newByteArray method

Signed-off-by: Baoyi Chen <chen.bao.yi@qq.com>
  • Loading branch information
leonchen83 committed Oct 29, 2020
1 parent 4530d9c commit bda623e
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -103,7 +103,18 @@ void recycle()
{
index = 0;
length = 0;
prevChunks = nextChunks;

int resize = 16;
if (prevChunks == null || nextChunks.size() > prevChunks.size())
{
prevChunks = nextChunks;
}

// keep prevChunks retain max resize elements
if (prevChunks.size() > resize)
{
prevChunks.subList(resize, prevChunks.size()).clear();
}
nextChunks = new ArrayList<>();
}
}

0 comments on commit bda623e

Please sign in to comment.