GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make bulk byte moving in ByteBuf faster · netty/netty@f0fe918

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • buffer/src/main/java/io/netty/buffer
    • PooledDirectByteBuf.java
    • UnpooledDirectByteBuf.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎buffer/src/main/java/io/netty/buffer/PooledDirectByteBuf.java‎

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 numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.netty.util.Recycler;
2020
import io.netty.util.internal.ObjectPool.Handle;
21+
import io.netty.util.internal.PlatformDependent;
2122

2223
import java.io.IOException;
2324
import java.io.InputStream;
@@ -110,14 +111,20 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
110111
checkDstIndex(index, length, dstIndex, dst.capacity());
111112
if (dst.hasArray()) {
112113
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-
}
119114
} 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+
}
121128
}
122129
return this;
123130
}
Collapse file

‎buffer/src/main/java/io/netty/buffer/UnpooledDirectByteBuf.java‎

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 numberDiff line numberDiff line change
@@ -362,14 +362,20 @@ public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
362362
checkDstIndex(index, length, dstIndex, dst.capacity());
363363
if (dst.hasArray()) {
364364
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-
}
371365
} 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+
}
373379
}
374380
return this;
375381
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.