Skip to content

Commit

Permalink
Revert "Add PooledSlicedByteBuf and PooledDuplicatedByteBuf"
Browse files Browse the repository at this point in the history
Motivation:
Currently the "derived" buffer will only ever be recycled if the release call is made on the "derived" object, and the "wrapped" buffer ends up being "fully released" (aka refcount goes to 0). From my experience this is not the common use case and thus the "derived" buffers will not be recycled.

Modifications:
- revert #3788

Result:
Less complexity, and less code to create new objects in majority of cases.
  • Loading branch information
Scottmitch committed Aug 26, 2015
1 parent 99f701f commit 77ff24b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 162 deletions.
17 changes: 2 additions & 15 deletions buffer/src/main/java/io/netty/buffer/AbstractDerivedByteBuf.java
Expand Up @@ -59,20 +59,12 @@ public final ByteBuf touch(Object hint) {

@Override
public final boolean release() {
if (unwrap().release()) {
deallocate();
return true;
}
return false;
return unwrap().release();
}

@Override
public final boolean release(int decrement) {
if (unwrap().release(decrement)) {
deallocate();
return true;
}
return false;
return unwrap().release(decrement);
}

@Override
Expand All @@ -84,9 +76,4 @@ public ByteBuffer internalNioBuffer(int index, int length) {
public ByteBuffer nioBuffer(int index, int length) {
return unwrap().nioBuffer(index, length);
}

/**
* Called when the wrapped {@link ByteBuf} was released due calling of {@link #release()} or {@link #release(int)}.
*/
protected void deallocate() { }
}
12 changes: 1 addition & 11 deletions buffer/src/main/java/io/netty/buffer/DuplicatedByteBuf.java
Expand Up @@ -33,28 +33,18 @@
*/
public class DuplicatedByteBuf extends AbstractDerivedByteBuf {

private ByteBuf buffer;
private final ByteBuf buffer;

public DuplicatedByteBuf(ByteBuf buffer) {
super(buffer.maxCapacity());
init(buffer);
}

DuplicatedByteBuf(int maxCapacity) {
super(maxCapacity);
}

final void init(ByteBuf buffer) {
maxCapacity(buffer.maxCapacity());
if (buffer instanceof DuplicatedByteBuf) {
this.buffer = ((DuplicatedByteBuf) buffer).buffer;
} else {
this.buffer = buffer;
}

setIndex(buffer.readerIndex(), buffer.writerIndex());
markReaderIndex();
markWriterIndex();
}

@Override
Expand Down
10 changes: 0 additions & 10 deletions buffer/src/main/java/io/netty/buffer/PooledByteBuf.java
Expand Up @@ -70,16 +70,6 @@ void initUnpooled(PoolChunk<T> chunk, int length) {
cache = null;
}

@Override
public ByteBuf slice(int index, int length) {
return PooledSlicedByteBuf.newInstance(this, index, length);
}

@Override
public ByteBuf duplicate() {
return PooledDuplicatedByteBuf.newInstance(this);
}

@Override
public final int capacity() {
return length;
Expand Down
56 changes: 0 additions & 56 deletions buffer/src/main/java/io/netty/buffer/PooledDuplicatedByteBuf.java

This file was deleted.

56 changes: 0 additions & 56 deletions buffer/src/main/java/io/netty/buffer/PooledSlicedByteBuf.java

This file was deleted.

19 changes: 5 additions & 14 deletions buffer/src/main/java/io/netty/buffer/SlicedByteBuf.java
Expand Up @@ -34,20 +34,12 @@
*/
public class SlicedByteBuf extends AbstractDerivedByteBuf {

private ByteBuf buffer;
private int adjustment;
private int length;
private final ByteBuf buffer;
private final int adjustment;
private final int length;

public SlicedByteBuf(ByteBuf buffer, int index, int length) {
super(length);
init(buffer, index, length);
}

SlicedByteBuf(int length) {
super(length);
}

final void init(ByteBuf buffer, int index, int length) {
if (index < 0 || index > buffer.capacity() - length) {
throw new IndexOutOfBoundsException(buffer + ".slice(" + index + ", " + length + ')');
}
Expand All @@ -63,9 +55,8 @@ final void init(ByteBuf buffer, int index, int length) {
adjustment = index;
}
this.length = length;
maxCapacity(length);
setIndex(0, length);
discardMarks();

writerIndex(length);
}

@Override
Expand Down

0 comments on commit 77ff24b

Please sign in to comment.