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 4e312d3 commit c36bffc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jetty.http2.client.transport.internal;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.function.BiFunction;

Expand Down Expand Up @@ -80,14 +81,21 @@ public Content.Chunk read(boolean fillInterestIfNeeded)
return null;
}
DataFrame frame = data.frame();
boolean terminal = !frame.getData().hasRemaining() && frame.isEndStream();
if (terminal)
ByteBuffer buffer = frame.getData();
if (!buffer.hasRemaining())
{
data.release();
responseSuccess(getHttpExchange(), null);
return Content.Chunk.EOF;
if (frame.isEndStream())
{
responseSuccess(getHttpExchange(), null);
return Content.Chunk.EOF;
}
else
{
return Content.Chunk.EMPTY;
}
}
return Content.Chunk.from(frame.getData(), terminal, data);
return Content.Chunk.from(buffer, frame.isEndStream(), data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ public Content.Chunk read(boolean fillInterestIfNeeded)
return null;
}
ByteBuffer byteBuffer = data.getByteBuffer();
boolean terminal = !byteBuffer.hasRemaining() && data.isLast();
if (terminal)
if (!byteBuffer.hasRemaining())
{
data.release();
responseSuccess(getHttpExchange(), null);
return Content.Chunk.EOF;
if (data.isLast())
{
responseSuccess(getHttpExchange(), null);
return Content.Chunk.EOF;
}
else
{
return Content.Chunk.EMPTY;
}
}
return Content.Chunk.from(byteBuffer, terminal, data);
return Content.Chunk.from(byteBuffer, data.isLast(), data);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ public Content.Chunk read()
if (last)
terminated = Content.Chunk.EOF;
}
boolean terminal = !buffer.hasRemaining() && last;
return terminal ? Content.Chunk.EOF : Content.Chunk.from(buffer, last);
if (!buffer.hasRemaining())
return last ? Content.Chunk.EOF : Content.Chunk.EMPTY;
return Content.Chunk.from(buffer, last);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,7 @@ public Content.Chunk read()
if (last)
terminated = Content.Chunk.EOF;
}
boolean terminal = !chunk.getByteBuffer().hasRemaining() && chunk.isLast();
if (terminal)
{
chunk.release();
return Content.Chunk.EOF;
}
return Content.Chunk.from(chunk.getByteBuffer().slice(), chunk.isLast(), chunk);
return chunk.slice();
}

@Override
Expand Down

0 comments on commit c36bffc

Please sign in to comment.