GeezerVison is showing github.com — Make bulk byte moving in ByteBuf faster (#16780) · netty/netty@37db5d7
File treeExpand file treeCollapse file tree Open diff view settings buffer/src/main/java/io/netty/buffer
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/PooledDirectByteBuf.java +14-7Lines changed: 14 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 18 | 18 |
| 19 | 19 | import io.netty.util.Recycler; | 20 | 20 | import io.netty.util.internal.ObjectPool.Handle; | | 21 | +import io.netty.util.internal.PlatformDependent; | 21 | 22 |
| 22 | 23 | import java.io.IOException; | 23 | 24 | import java.io.InputStream; | @@ -110,14 +111,20 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { | 110 | 111 | checkDstIndex(index, length, dstIndex, dst.capacity()); | 111 | 112 | if (dst.hasArray()) { | 112 | 113 | getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); | 113 | | - } else if (dst.nioBufferCount() > 0) { | 114 | | - for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) { | 115 | | - int bbLen = bb.remaining(); | 116 | | - getBytes(index, bb); | 117 | | - index += bbLen; | 118 | | - } | 119 | 114 | } else { | 120 | | - dst.setBytes(dstIndex, this, index, length); | | 115 | + ByteBuf unwrapped = dst instanceof WrappedByteBuf ? dst.unwrap() : dst; | | 116 | + if (unwrapped instanceof AbstractByteBuf) { | | 117 | + ByteBuffer dstBuf = unwrapped.internalNioBuffer(dstIndex, length); | | 118 | + PlatformDependent.absolutePut(dstBuf, dstBuf.position(), memory, idx(index), length); | | 119 | + } else if (dst.nioBufferCount() > 0) { | | 120 | + for (ByteBuffer bb : dst.nioBuffers(dstIndex, length)) { | | 121 | + int bbLen = bb.remaining(); | | 122 | + getBytes(index, bb); | | 123 | + index += bbLen; | | 124 | + } | | 125 | + } else { | | 126 | + dst.setBytes(dstIndex, this, index, length); | | 127 | + } | 121 | 128 | } | 122 | 129 | return this; | 123 | 130 | } | |
Collapse file Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java +13-7Lines changed: 13 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -362,14 +362,20 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { | 362 | 362 | checkDstIndex(index, length, dstIndex, dst.capacity()); | 363 | 363 | if (dst.hasArray()) { | 364 | 364 | getBytes(index, dst.array(), dst.arrayOffset() + dstIndex, length); | 365 | | - } else if (dst.nioBufferCount() > 0) { | 366 | | - for (ByteBuffer bb: dst.nioBuffers(dstIndex, length)) { | 367 | | - int bbLen = bb.remaining(); | 368 | | - getBytes(index, bb); | 369 | | - index += bbLen; | 370 | | - } | 371 | 365 | } else { | 372 | | - dst.setBytes(dstIndex, this, index, length); | | 366 | + ByteBuf unwrapped = dst instanceof WrappedByteBuf ? dst.unwrap() : dst; | | 367 | + if (unwrapped instanceof AbstractByteBuf) { | | 368 | + ByteBuffer dstBuf = unwrapped.internalNioBuffer(dstIndex, length); | | 369 | + PlatformDependent.absolutePut(dstBuf, dstBuf.position(), buffer, index, length); | | 370 | + } else if (dst.nioBufferCount() > 0) { | | 371 | + for (ByteBuffer bb : dst.nioBuffers(dstIndex, length)) { | | 372 | + int bbLen = bb.remaining(); | | 373 | + getBytes(index, bb); | | 374 | + index += bbLen; | | 375 | + } | | 376 | + } else { | | 377 | + dst.setBytes(dstIndex, this, index, length); | | 378 | + } | 373 | 379 | } | 374 | 380 | return this; | 375 | 381 | } | |
|