CompositeByteBuf.isDirect() should return true if its only backed by direct buffers
This commit is contained in:
parent
a74149e984
commit
2b9a07cac9
@ -430,10 +430,16 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
|
||||
@Override
|
||||
public boolean isDirect() {
|
||||
if (components.size() == 1) {
|
||||
return components.get(0).buf.isDirect();
|
||||
int size = components.size();
|
||||
if (size == 0) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (!components.get(i).buf.isDirect()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -776,4 +776,20 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
||||
public void testInternalNioBuffer() {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testisDirectMultipleBufs() {
|
||||
CompositeByteBuf buf = freeLater(compositeBuffer());
|
||||
assertFalse(buf.isDirect());
|
||||
|
||||
buf.addComponent(directBuffer().writeByte(1));
|
||||
|
||||
assertTrue(buf.isDirect());
|
||||
buf.addComponent(directBuffer().writeByte(1));
|
||||
assertTrue(buf.isDirect());
|
||||
|
||||
buf.addComponent(buffer().writeByte(1));
|
||||
assertFalse(buf.isDirect());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user