centic9 commented on pull request #209:
URL: https://github.com/apache/poi/pull/209#issuecomment-788094928
It's fine, "new ByteArrayOutputStream(int size)" would allow to populate
the stream without additional allocation, but toByteArray() performs a full
array-copy again, so doing it ourselves should avoid this additional copying.
In one of my projects I use the following helper class which avoids all the
manual array-positioning and copying yourself and keeps using the
ByteArrayOutputStream.
```
class NonCopyingByteArrayOutputStream extends ByteArrayOutputStream {
public NonCopyingByteArrayOutputStream(int size) {
super(size);
}
public synchronized byte[] toByteArrayDirect() {
return buf;
}
}
```
In general I find it useful to verify such changes with results "before" and
"after" via some tests as sometimes the JDK applies complicated optimizations
which can cause changes to actually cause a slowdown.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]