This commit is contained in:
parent
6cd9045b96
commit
77b4ec7e1b
@ -233,8 +233,8 @@ abstract class PoolArena<T> {
|
|||||||
allocate(parent.threadCache.get(), buf, newCapacity);
|
allocate(parent.threadCache.get(), buf, newCapacity);
|
||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
memoryCopy(
|
memoryCopy(
|
||||||
oldMemory, oldOffset + readerIndex,
|
oldMemory, oldOffset,
|
||||||
buf.memory, buf.offset + readerIndex, writerIndex - readerIndex);
|
buf.memory, buf.offset, oldCapacity);
|
||||||
} else if (newCapacity < oldCapacity) {
|
} else if (newCapacity < oldCapacity) {
|
||||||
if (readerIndex < newCapacity) {
|
if (readerIndex < newCapacity) {
|
||||||
if (writerIndex > newCapacity) {
|
if (writerIndex > newCapacity) {
|
||||||
|
@ -141,8 +141,8 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
ByteBuffer oldBuffer = buffer;
|
ByteBuffer oldBuffer = buffer;
|
||||||
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
||||||
oldBuffer.position(readerIndex).limit(writerIndex);
|
oldBuffer.position(0).limit(oldBuffer.capacity());
|
||||||
newBuffer.position(readerIndex).limit(writerIndex);
|
newBuffer.position(0).limit(oldBuffer.capacity());
|
||||||
newBuffer.put(oldBuffer);
|
newBuffer.put(oldBuffer);
|
||||||
newBuffer.clear();
|
newBuffer.clear();
|
||||||
setByteBuffer(newBuffer);
|
setByteBuffer(newBuffer);
|
||||||
|
@ -112,7 +112,7 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
int oldCapacity = array.length;
|
int oldCapacity = array.length;
|
||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
byte[] newArray = new byte[newCapacity];
|
byte[] newArray = new byte[newCapacity];
|
||||||
System.arraycopy(array, readerIndex(), newArray, readerIndex(), readableBytes());
|
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||||
setArray(newArray);
|
setArray(newArray);
|
||||||
} else if (newCapacity < oldCapacity) {
|
} else if (newCapacity < oldCapacity) {
|
||||||
byte[] newArray = new byte[newCapacity];
|
byte[] newArray = new byte[newCapacity];
|
||||||
|
@ -145,8 +145,8 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
|||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
ByteBuffer oldBuffer = buffer;
|
ByteBuffer oldBuffer = buffer;
|
||||||
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
ByteBuffer newBuffer = ByteBuffer.allocateDirect(newCapacity);
|
||||||
oldBuffer.position(readerIndex).limit(writerIndex);
|
oldBuffer.position(0).limit(oldBuffer.capacity());
|
||||||
newBuffer.position(readerIndex).limit(writerIndex);
|
newBuffer.position(0).limit(oldBuffer.capacity());
|
||||||
newBuffer.put(oldBuffer);
|
newBuffer.put(oldBuffer);
|
||||||
newBuffer.clear();
|
newBuffer.clear();
|
||||||
setByteBuffer(newBuffer);
|
setByteBuffer(newBuffer);
|
||||||
|
@ -52,4 +52,15 @@ public class DuplicateByteBufTest extends AbstractByteBufTest {
|
|||||||
super.testInternalNioBuffer();
|
super.testInternalNioBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// See https://github.com/netty/netty/issues/1800
|
||||||
|
@Test
|
||||||
|
public void testIncreaseCapacityWrapped() {
|
||||||
|
ByteBuf wrapped = buffer.unwrap();
|
||||||
|
wrapped.writeByte(0);
|
||||||
|
wrapped.readerIndex(wrapped.readerIndex() + 1);
|
||||||
|
buffer.writerIndex(buffer.writerIndex() + 1);
|
||||||
|
wrapped.capacity(wrapped.capacity() * 2);
|
||||||
|
|
||||||
|
assertEquals((byte) 0, buffer.readByte());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user