Make PooledByteBuf recyclable regardless its maxCapacity
- Make AbstractByteBuf.maxCapacity internally mutable so that PooledByteBuf is completely recyclable
This commit is contained in:
parent
9396246fe9
commit
2d7c6f8ee1
@ -39,7 +39,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
||||
private int markedReaderIndex;
|
||||
private int markedWriterIndex;
|
||||
|
||||
private final int maxCapacity;
|
||||
private int maxCapacity;
|
||||
|
||||
private SwappedByteBuf swappedBuf;
|
||||
|
||||
@ -55,6 +55,10 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
||||
return maxCapacity;
|
||||
}
|
||||
|
||||
protected final void maxCapacity(int maxCapacity) {
|
||||
this.maxCapacity = maxCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readerIndex() {
|
||||
return readerIndex;
|
||||
@ -216,7 +220,7 @@ public abstract class AbstractByteBuf implements ByteBuf {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void adjustMarkers(int decrement) {
|
||||
protected final void adjustMarkers(int decrement) {
|
||||
int markedReaderIndex = this.markedReaderIndex;
|
||||
if (markedReaderIndex <= decrement) {
|
||||
this.markedReaderIndex = 0;
|
||||
|
@ -31,16 +31,14 @@ final class PooledDirectByteBuf extends PooledByteBuf<ByteBuffer> {
|
||||
private static final Recycler<PooledDirectByteBuf> RECYCLER = new Recycler<PooledDirectByteBuf>() {
|
||||
@Override
|
||||
protected PooledDirectByteBuf newObject(Handle handle) {
|
||||
return new PooledDirectByteBuf(handle, Integer.MAX_VALUE);
|
||||
return new PooledDirectByteBuf(handle, 0);
|
||||
}
|
||||
};
|
||||
|
||||
static PooledDirectByteBuf newInstance(int maxCapacity) {
|
||||
if (maxCapacity == Integer.MAX_VALUE) {
|
||||
return RECYCLER.get();
|
||||
} else {
|
||||
return new PooledDirectByteBuf(null, maxCapacity);
|
||||
}
|
||||
PooledDirectByteBuf buf = RECYCLER.get();
|
||||
buf.maxCapacity(maxCapacity);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private PooledDirectByteBuf(Recycler.Handle recyclerHandle, int maxCapacity) {
|
||||
|
@ -30,16 +30,14 @@ final class PooledHeapByteBuf extends PooledByteBuf<byte[]> {
|
||||
private static final Recycler<PooledHeapByteBuf> RECYCLER = new Recycler<PooledHeapByteBuf>() {
|
||||
@Override
|
||||
protected PooledHeapByteBuf newObject(Handle handle) {
|
||||
return new PooledHeapByteBuf(handle, Integer.MAX_VALUE);
|
||||
return new PooledHeapByteBuf(handle, 0);
|
||||
}
|
||||
};
|
||||
|
||||
static PooledHeapByteBuf newInstance(int maxCapacity) {
|
||||
if (maxCapacity == Integer.MAX_VALUE) {
|
||||
return RECYCLER.get();
|
||||
} else {
|
||||
return new PooledHeapByteBuf(null, maxCapacity);
|
||||
}
|
||||
PooledHeapByteBuf buf = RECYCLER.get();
|
||||
buf.maxCapacity(maxCapacity);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private PooledHeapByteBuf(Recycler.Handle recyclerHandle, int maxCapacity) {
|
||||
|
@ -35,16 +35,14 @@ final class PooledUnsafeDirectByteBuf extends PooledByteBuf<ByteBuffer> {
|
||||
private static final Recycler<PooledUnsafeDirectByteBuf> RECYCLER = new Recycler<PooledUnsafeDirectByteBuf>() {
|
||||
@Override
|
||||
protected PooledUnsafeDirectByteBuf newObject(Handle handle) {
|
||||
return new PooledUnsafeDirectByteBuf(handle, Integer.MAX_VALUE);
|
||||
return new PooledUnsafeDirectByteBuf(handle, 0);
|
||||
}
|
||||
};
|
||||
|
||||
static PooledUnsafeDirectByteBuf newInstance(int maxCapacity) {
|
||||
if (maxCapacity == Integer.MAX_VALUE) {
|
||||
return RECYCLER.get();
|
||||
} else {
|
||||
return new PooledUnsafeDirectByteBuf(null, maxCapacity);
|
||||
}
|
||||
PooledUnsafeDirectByteBuf buf = RECYCLER.get();
|
||||
buf.maxCapacity(maxCapacity);
|
||||
return buf;
|
||||
}
|
||||
|
||||
private long memoryAddress;
|
||||
|
Loading…
Reference in New Issue
Block a user