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:
parent
40b4c35574
commit
65c2a6ed46
@ -32,7 +32,7 @@ import java.nio.charset.Charset;
|
|||||||
/**
|
/**
|
||||||
* A skeletal implementation of a buffer.
|
* 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);
|
static final ResourceLeakDetector<ByteBuf> leakDetector = new ResourceLeakDetector<ByteBuf>(ByteBuf.class);
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
|
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
|
||||||
return new DefaultCompositeByteBuf(this, false, maxNumComponents);
|
return new CompositeByteBuf(this, false, maxNumComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -163,7 +163,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompositeByteBuf compositeDirectBuffer(int maxNumComponents) {
|
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) {
|
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
File diff suppressed because it is too large
Load Diff
@ -31,7 +31,7 @@ import java.nio.charset.Charset;
|
|||||||
/**
|
/**
|
||||||
* An empty {@link ByteBuf} whose capacity and maximum capacity are all {@code 0}.
|
* 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 ByteBuffer EMPTY_BYTE_BUFFER = ByteBuffer.allocateDirect(0);
|
||||||
private static final long EMPTY_BYTE_BUFFER_ADDRESS;
|
private static final long EMPTY_BYTE_BUFFER_ADDRESS;
|
||||||
|
@ -24,7 +24,7 @@ import java.nio.channels.GatheringByteChannel;
|
|||||||
import java.nio.channels.ScatteringByteChannel;
|
import java.nio.channels.ScatteringByteChannel;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
public final class SwappedByteBuf implements ByteBuf {
|
public final class SwappedByteBuf extends ByteBuf {
|
||||||
|
|
||||||
private final ByteBuf buf;
|
private final ByteBuf buf;
|
||||||
private final ByteOrder order;
|
private final ByteOrder order;
|
||||||
|
@ -274,7 +274,7 @@ public final class Unpooled {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!components.isEmpty()) {
|
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:
|
default:
|
||||||
for (ByteBuf b: buffers) {
|
for (ByteBuf b: buffers) {
|
||||||
if (b.isReadable()) {
|
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()) {
|
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.
|
* Returns a new big-endian composite buffer with no components.
|
||||||
*/
|
*/
|
||||||
public static CompositeByteBuf compositeBuffer(int maxNumComponents) {
|
public static CompositeByteBuf compositeBuffer(int maxNumComponents) {
|
||||||
return new DefaultCompositeByteBuf(ALLOC, false, maxNumComponents);
|
return new CompositeByteBuf(ALLOC, false, maxNumComponents);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
* A {@link ByteBuf} implementation that wraps another buffer to prevent a user from increasing or decreasing the
|
||||||
* wrapped buffer's reference count.
|
* wrapped buffer's reference count.
|
||||||
*/
|
*/
|
||||||
final class UnreleasableByteBuf implements ByteBuf {
|
final class UnreleasableByteBuf extends ByteBuf {
|
||||||
|
|
||||||
private final ByteBuf buf;
|
private final ByteBuf buf;
|
||||||
private SwappedByteBuf swappedBuf;
|
private SwappedByteBuf swappedBuf;
|
||||||
|
@ -33,7 +33,7 @@ import java.nio.charset.Charset;
|
|||||||
/**
|
/**
|
||||||
* Special {@link ByteBuf} implementation which is used by the {@link ReplayingDecoder}
|
* 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;
|
private static final Signal REPLAY = ReplayingDecoder.REPLAY;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user