Skip to content

Commit f6e3239

Browse files
authored
Merge pull request #47198 from franz1981/use_raw_netty_buffers
Save additional copies on byte[] and String REST resources
2 parents 30f2f55 + 7590321 commit f6e3239

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

independent-projects/resteasy-reactive/server/vertx/src/main/java/org/jboss/resteasy/reactive/server/vertx/VertxResteasyReactiveRequestContext.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
import org.jboss.resteasy.reactive.server.spi.ServerRestHandler;
3434
import org.jboss.resteasy.reactive.spi.ThreadSetupAction;
3535

36+
import io.netty.buffer.ByteBufUtil;
3637
import io.netty.buffer.Unpooled;
3738
import io.netty.channel.EventLoop;
3839
import io.netty.handler.codec.http.HttpHeaderNames;
3940
import io.netty.handler.codec.http.QueryStringDecoder;
41+
import io.netty.util.CharsetUtil;
4042
import io.netty.util.concurrent.ScheduledFuture;
43+
import io.quarkus.vertx.utils.NoBoundChecksBuffer;
4144
import io.quarkus.vertx.utils.VertxJavaIoContext;
4245
import io.quarkus.vertx.utils.VertxOutputStream;
4346
import io.vertx.core.AsyncResult;
@@ -46,6 +49,7 @@
4649
import io.vertx.core.MultiMap;
4750
import io.vertx.core.Vertx;
4851
import io.vertx.core.buffer.Buffer;
52+
import io.vertx.core.buffer.impl.VertxByteBufAllocator;
4953
import io.vertx.core.http.HttpServerRequest;
5054
import io.vertx.core.http.HttpServerResponse;
5155
import io.vertx.core.http.impl.Http1xServerResponse;
@@ -399,13 +403,17 @@ public boolean headWritten() {
399403

400404
@Override
401405
public ServerHttpResponse end(byte[] data) {
402-
response.end(Buffer.buffer(data), null);
406+
var buffer = VertxByteBufAllocator.POOLED_ALLOCATOR.directBuffer(data.length);
407+
buffer.writeBytes(data);
408+
response.end(new NoBoundChecksBuffer(buffer), null);
403409
return this;
404410
}
405411

406412
@Override
407413
public ServerHttpResponse end(String data) {
408-
response.end(Buffer.buffer(data), null);
414+
var buffer = VertxByteBufAllocator.POOLED_ALLOCATOR.directBuffer(ByteBufUtil.utf8MaxBytes(data.length()));
415+
buffer.writeCharSequence(data, CharsetUtil.UTF_8);
416+
response.end(new NoBoundChecksBuffer(buffer), null);
409417
return this;
410418
}
411419

0 commit comments

Comments
 (0)