You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by GitBox <gi...@apache.org> on 2021/03/01 16:42:55 UTC

[GitHub] [poi] centic9 commented on pull request #209: Improve performance of Bitmap#setData

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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org