Not cache SwappedByteBuf in AbstractByteBuf to reduce memory footprint.

Motivation:

We should not cache the SwappedByteBuf in AbstractByteBuf to reduce the memory footprint.

Modifications:

Not cache the SwappedByteBuf.

Result:

Less memory footprint.
This commit is contained in:
Norman Maurer 2016-04-13 15:34:06 +02:00
parent 2537880e5d
commit 4ddb81f36f
2 changed files with 2 additions and 10 deletions

View File

@ -57,11 +57,8 @@ public abstract class AbstractByteBuf extends ByteBuf {
int writerIndex; int writerIndex;
private int markedReaderIndex; private int markedReaderIndex;
private int markedWriterIndex; private int markedWriterIndex;
private int maxCapacity; private int maxCapacity;
private SwappedByteBuf swappedBuf;
protected AbstractByteBuf(int maxCapacity) { protected AbstractByteBuf(int maxCapacity) {
if (maxCapacity < 0) { if (maxCapacity < 0) {
throw new IllegalArgumentException("maxCapacity: " + maxCapacity + " (expected: >= 0)"); throw new IllegalArgumentException("maxCapacity: " + maxCapacity + " (expected: >= 0)");
@ -313,12 +310,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
if (endianness == order()) { if (endianness == order()) {
return this; return this;
} }
return newSwappedByteBuf();
SwappedByteBuf swappedBuf = this.swappedBuf;
if (swappedBuf == null) {
this.swappedBuf = swappedBuf = newSwappedByteBuf();
}
return swappedBuf;
} }
/** /**

View File

@ -53,7 +53,7 @@ public abstract class AbstractPooledByteBufTest extends AbstractByteBufTest {
ByteBuf buf2 = newBuffer(capacity); ByteBuf buf2 = newBuffer(capacity);
assertSame(unwrapIfNeeded(buf), unwrapIfNeeded(buf2)); assertEquals(unwrapIfNeeded(buf), unwrapIfNeeded(buf2));
buf2.writeShort(1); buf2.writeShort(1);