DefaultDataBuffer improvements

DefaultDataBuffer.grow(int):
- Copy only the remaining data
- Update readPosition/writePosition
This commit is contained in:
Violeta Georgieva
2016-10-18 13:14:55 +03:00
parent ec1eb14280
commit 882b075fdf
2 changed files with 21 additions and 1 deletions

View File

@@ -272,10 +272,13 @@ public class DefaultDataBuffer implements DataBuffer {
ByteBuffer.allocate(minCapacity));
// Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer
((Buffer) oldBuffer).position(this.readPosition);
final int remaining = readableByteCount();
((Buffer) oldBuffer).position(this.readPosition).limit(this.writePosition);
newBuffer.put(oldBuffer);
this.byteBuffer = newBuffer;
this.readPosition = 0;
this.writePosition = remaining;
oldBuffer.clear();
}