From 4ddb81f36fc1ccf244250124d91eda98dadef779 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 13 Apr 2016 15:34:06 +0200 Subject: [PATCH] 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. --- .../src/main/java/io/netty/buffer/AbstractByteBuf.java | 10 +--------- .../io/netty/buffer/AbstractPooledByteBufTest.java | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java index 4679caeee6..6e8263f4aa 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java @@ -57,11 +57,8 @@ public abstract class AbstractByteBuf extends ByteBuf { int writerIndex; private int markedReaderIndex; private int markedWriterIndex; - private int maxCapacity; - private SwappedByteBuf swappedBuf; - protected AbstractByteBuf(int maxCapacity) { if (maxCapacity < 0) { throw new IllegalArgumentException("maxCapacity: " + maxCapacity + " (expected: >= 0)"); @@ -313,12 +310,7 @@ public abstract class AbstractByteBuf extends ByteBuf { if (endianness == order()) { return this; } - - SwappedByteBuf swappedBuf = this.swappedBuf; - if (swappedBuf == null) { - this.swappedBuf = swappedBuf = newSwappedByteBuf(); - } - return swappedBuf; + return newSwappedByteBuf(); } /** diff --git a/buffer/src/test/java/io/netty/buffer/AbstractPooledByteBufTest.java b/buffer/src/test/java/io/netty/buffer/AbstractPooledByteBufTest.java index 46d07f8f2a..a1a6fadb6a 100644 --- a/buffer/src/test/java/io/netty/buffer/AbstractPooledByteBufTest.java +++ b/buffer/src/test/java/io/netty/buffer/AbstractPooledByteBufTest.java @@ -53,7 +53,7 @@ public abstract class AbstractPooledByteBufTest extends AbstractByteBufTest { ByteBuf buf2 = newBuffer(capacity); - assertSame(unwrapIfNeeded(buf), unwrapIfNeeded(buf2)); + assertEquals(unwrapIfNeeded(buf), unwrapIfNeeded(buf2)); buf2.writeShort(1);