Skip to content

Commit

Permalink
#8993: optimize for EMPTY
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Dec 2, 2022
1 parent 71e11a3 commit 90e629d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,19 @@ public Runnable onTrailer(HeadersFrame frame)
private Content.Chunk createChunk(Stream.Data data)
{
DataFrame frame = data.frame();
if (frame.isEndStream() && frame.remaining() == 0)
return Content.Chunk.EOF;

ByteBuffer byteBuffer = frame.getData();
if (!byteBuffer.hasRemaining())
{
// We must NOT retain because we are not passing the
// ByteBuffer to the Chunk.
if (frame.isEndStream())
return Content.Chunk.EOF;
else
return Content.Chunk.EMPTY;
}
// We need to retain because we are passing the ByteBuffer to the Chunk.
data.retain();
return Content.Chunk.from(frame.getData(), frame.isEndStream(), data);
return Content.Chunk.from(byteBuffer, frame.isEndStream(), data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,19 @@ public Runnable onTrailer(HeadersFrame frame)

private Content.Chunk createChunk(Stream.Data data)
{
if (data == Stream.Data.EOF)
return Content.Chunk.EOF;

ByteBuffer byteBuffer = data.getByteBuffer();
if (!byteBuffer.hasRemaining())
{
// As we are NOT passing the ByteBuffer to the Chunk,
// we must not retain.
if (data.isLast())
return Content.Chunk.EOF;
else
return Content.Chunk.EMPTY;
}
// As we are passing the ByteBuffer to the Chunk we need to retain.
data.retain();
return Content.Chunk.from(data.getByteBuffer(), data.isLast(), data);
return Content.Chunk.from(byteBuffer, data.isLast(), data);
}

@Override
Expand Down

0 comments on commit 90e629d

Please sign in to comment.