You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/05/10 21:24:44 UTC

[GitHub] [commons-codec] apinske commented on a change in pull request #85: Reduce byte[] allocations by reusing buffers

apinske commented on a change in pull request #85:
URL: https://github.com/apache/commons-codec/pull/85#discussion_r629693641



##########
File path: src/main/java/org/apache/commons/codec/binary/BaseNCodec.java
##########
@@ -569,7 +570,11 @@ public String encodeToString(final byte[] pArray) {
      */
     protected byte[] ensureBufferSize(final int size, final Context context){
         if (context.buffer == null) {
-            context.buffer = new byte[Math.max(size, getDefaultBufferSize())];
+            int bufferSize = Math.max(size, getDefaultBufferSize());
+            if (context.bufferCache == null || context.bufferCache.length != bufferSize) {

Review comment:
       Base16 seems to have variable sizes. I don't understand the inner workings well enough currently. Will have to dig deeper. Wouldn't mind if you took over, though. :)




-- 
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