Optimize the way messages are added from one MessageList to another one

This commit is contained in:
Norman Maurer 2013-06-10 14:07:25 +02:00
parent 383bb80d1e
commit 68c737f0c0
5 changed files with 33 additions and 10 deletions

View File

@ -116,10 +116,10 @@ public abstract class ByteToMessageDecoder extends ChannelInboundHandlerAdapter
int size = msgs.size();
for (int i = 0; i < size; i ++) {
Object m = msgs.get(i);
// handler was removed in the loop
// handler was removed in the loop so now copy over all remaining messages
if (ctx.isRemoved()) {
out.add(m);
continue;
out.add(msgs, i, size - i);
return;
}
if (m instanceof ByteBuf) {
ByteBuf data = (ByteBuf) m;

View File

@ -65,8 +65,16 @@ public abstract class MessageToByteEncoder<I> extends ChannelOutboundHandlerAdap
ByteBuf buf = null;
int size = msgs.size();
for (int i = 0; i < size; i ++) {
// handler was removed in the loop so now copy over all remaining messages
if (ctx.isRemoved()) {
if (buf != null && buf.isReadable()) {
out.add(buf);
}
out.add(msgs, i, size - i);
break;
}
Object m = msgs.get(i);
if (!ctx.isRemoved() && acceptOutboundMessage(m)) {
if (acceptOutboundMessage(m)) {
@SuppressWarnings("unchecked")
I cast = (I) m;
if (buf == null) {

View File

@ -62,8 +62,14 @@ public abstract class MessageToMessageDecoder<I> extends ChannelInboundHandlerAd
try {
int size = msgs.size();
for (int i = 0; i < size; i ++) {
// handler was removed in the loop so now copy over all remaining messages
if (ctx.isRemoved()) {
out.add(msgs, i, size - i);
return;
}
Object m = msgs.get(i);
if (!ctx.isRemoved() && acceptInboundMessage(m)) {
if (acceptInboundMessage(m)) {
@SuppressWarnings("unchecked")
I cast = (I) m;
try {

View File

@ -63,8 +63,13 @@ public abstract class MessageToMessageEncoder<I> extends ChannelOutboundHandlerA
try {
int size = msgs.size();
for (int i = 0; i < size; i ++) {
// handler was removed in the loop so now copy over all remaining messages
if (ctx.isRemoved()) {
out.add(msgs, i, size - i);
break;
}
Object m = msgs.get(i);
if (!ctx.isRemoved() && acceptOutboundMessage(m)) {
if (acceptOutboundMessage(m)) {
@SuppressWarnings("unchecked")
I cast = (I) m;
try {

View File

@ -167,6 +167,14 @@ public final class MessageList<T> {
return this;
}
public MessageList<T> add(MessageList<T> src) {
return add(src, 0, src.size());
}
public MessageList<T> add(MessageList<T> src, int srcIdx, int srcLen) {
return add(src.elements, srcIdx, srcLen);
}
public MessageList<T> clear() {
Arrays.fill(elements, 0, size, null);
size = 0;
@ -190,10 +198,6 @@ public final class MessageList<T> {
return (MessageList<U>) this;
}
public T[] array() {
return elements;
}
public boolean forEach(MessageListProcessor<? super T> proc) {
if (proc == null) {
throw new NullPointerException("proc");