franz1981 commented on pull request #3711:
URL: https://github.com/apache/activemq-artemis/pull/3711#issuecomment-908941654
I see that I'm relying (write side) on the knowledge that incoming data is
using a composite readable buffer, while the whole complete version should
account of Netty/NIO ones too, to save the copy to happen, looking more as
```java
public void addBytes(ReadableBuffer data) throws Exception {
parseLargeMessage(data);
boolean releaseBuffer = true;
ByteBuf writeBuffer = null;
try {
if (!data.hasArray()) {
// try access some direct buffer in
if (data instanceof ReadableBuffer.ByteBufferReader) {
final ByteBuffer nioBuffer = data.byteBuffer();
if (nioBuffer.isDirect()) {
writeBuffer = Unpooled.wrappedBuffer(nioBuffer);
releaseBuffer = false;
}
} else if (data instanceof NettyReadable) {
final ByteBuf nettyBuffer = ((NettyReadable)
data).getByteBuf();
if (nettyBuffer.isDirect()) {
writeBuffer = nettyBuffer;
releaseBuffer = false;
}
}
}
if (writeBuffer == null) {
// perform copy of data
final int bytes = data.remaining();
writeBuffer = PooledByteBufAllocator.DEFAULT.directBuffer(bytes,
bytes);
data.get(new NettyWritable(writeBuffer));
}
largeBody.addBytes(new ChannelBufferWrapper(writeBuffer, true,
true));
} finally {
if (releaseBuffer) {
if (writeBuffer != null) {
writeBuffer.release();
}
}
}
}
```
It seems very complicate to me, so I prefer to leave it as it is, @gemmellr
wdyt?
While I need your advice on the small change I've made on
https://github.com/apache/activemq-artemis/pull/3711/commits/7f56ab813f8eb1e5ceb7dba4d214ee6507d9f386:
is it safe?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]