Make AbstractMemoryHttpData generate less garbage

This commit is contained in:
Trustin Lee 2013-06-20 15:51:56 +09:00
parent 58c33d71db
commit dc6e2cd625

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.http.multipart; package io.netty.handler.codec.http.multipart;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.CompositeByteBuf;
import io.netty.handler.codec.http.HttpConstants; import io.netty.handler.codec.http.HttpConstants;
import java.io.File; import java.io.File;
@ -91,8 +92,15 @@ public abstract class AbstractMemoryHttpData extends AbstractHttpData {
size += localsize; size += localsize;
if (byteBuf == null) { if (byteBuf == null) {
byteBuf = buffer; byteBuf = buffer;
} else if (byteBuf instanceof CompositeByteBuf) {
CompositeByteBuf cbb = (CompositeByteBuf) byteBuf;
cbb.addComponent(buffer);
cbb.writerIndex(cbb.writerIndex() + buffer.readableBytes());
} else { } else {
byteBuf = wrappedBuffer(byteBuf, buffer); CompositeByteBuf cbb = compositeBuffer();
cbb.addComponent(buffer);
cbb.writerIndex(buffer.readableBytes());
byteBuf = cbb;
} }
} }
if (last) { if (last) {