Make ByteBuf an abstract class rather than an interface

- 5% improvement in throughput (HelloWorldServer example)
- Made CompositeByteBuf a concrete class (renamed from DefaultCompositeByteBuf) because there's no multiple inheritance in Java

Fixes #1536
This commit is contained in:
Trustin Lee 2013-07-08 13:32:33 +09:00
parent 40b4c35574
commit 65c2a6ed46
10 changed files with 1535 additions and 1856 deletions

View File

@ -32,7 +32,7 @@ import java.nio.charset.Charset;
/**
* A skeletal implementation of a buffer.
*/
public abstract class AbstractByteBuf implements ByteBuf {
public abstract class AbstractByteBuf extends ByteBuf {
static final ResourceLeakDetector<ByteBuf> leakDetector = new ResourceLeakDetector<ByteBuf>(ByteBuf.class);

View File

@ -153,7 +153,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
return new DefaultCompositeByteBuf(this, false, maxNumComponents);
return new CompositeByteBuf(this, false, maxNumComponents);
}
@Override
@ -163,7 +163,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
@Override
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
return new DefaultCompositeByteBuf(this, true, maxNumComponents);
return new CompositeByteBuf(this, true, maxNumComponents);
}
private static void validate(int initialCapacity, int maxCapacity) {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ import java.nio.charset.Charset;
/**
* An empty {@link ByteBuf} whose capacity and maximum capacity are all {@code 0}.
*/
public final class EmptyByteBuf implements ByteBuf {
public final class EmptyByteBuf extends ByteBuf {
private static final ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.allocateDirect(0);
private static final long EMPTY_BYTE_BUFFER_ADDRESS;

View File

@ -24,7 +24,7 @@ import java.nio.channels.GatheringByteChannel;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
public final class SwappedByteBuf implements ByteBuf {
public final class SwappedByteBuf extends ByteBuf {
private final ByteBuf buf;
private final ByteOrder order;

View File

@ -274,7 +274,7 @@ public final class Unpooled {
}
if (!components.isEmpty()) {
return new DefaultCompositeByteBuf(ALLOC, false, maxNumComponents, components);
return new CompositeByteBuf(ALLOC, false, maxNumComponents, components);
}
}
@ -298,7 +298,7 @@ public final class Unpooled {
default:
for (ByteBuf b: buffers) {
if (b.isReadable()) {
return new DefaultCompositeByteBuf(ALLOC, false, maxNumComponents, buffers);
return new CompositeByteBuf(ALLOC, false, maxNumComponents, buffers);
}
}
}
@ -332,7 +332,7 @@ public final class Unpooled {
}
if (!components.isEmpty()) {
return new DefaultCompositeByteBuf(ALLOC, false, maxNumComponents, components);
return new CompositeByteBuf(ALLOC, false, maxNumComponents, components);
}
}
@ -350,7 +350,7 @@ public final class Unpooled {
* Returns a new big-endian composite buffer with no components.
*/
public static CompositeByteBuf compositeBuffer(int maxNumComponents) {
return new DefaultCompositeByteBuf(ALLOC, false, maxNumComponents);
return new CompositeByteBuf(ALLOC, false, maxNumComponents);
}
/**

View File

@ -30,7 +30,7 @@ import java.nio.charset.Charset;
* A {@link ByteBuf} implementation that wraps another buffer to prevent a user from increasing or decreasing the
* wrapped buffer's reference count.
*/
final class UnreleasableByteBuf implements ByteBuf {
final class UnreleasableByteBuf extends ByteBuf {
private final ByteBuf buf;
private SwappedByteBuf swappedBuf;

View File

@ -33,7 +33,7 @@ import java.nio.charset.Charset;
/**
* Special {@link ByteBuf} implementation which is used by the {@link ReplayingDecoder}
*/
final class ReplayingDecoderBuffer implements ByteBuf {
final class ReplayingDecoderBuffer extends ByteBuf {
private static final Signal REPLAY = ReplayingDecoder.REPLAY;