Skip to content

Commit 9e0aef4

Browse files
committed
complete change to add more alloc methods
1 parent 4995dc4 commit 9e0aef4

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/main/java/com/fasterxml/jackson/core/util/BufferRecycler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,26 @@ public enum CharBufferType {
5757

5858
public BufferRecycler() { }
5959

60-
public final byte[] allocByteBuffer(ByteBufferType type)
60+
public final byte[] allocByteBuffer(ByteBufferType type) {
61+
return allocByteBuffer(type, 0);
62+
}
63+
64+
public final byte[] allocByteBuffer(ByteBufferType type, int minSize)
6165
{
62-
int ix = type.ordinal();
66+
final int ix = type.ordinal();
67+
final int DEF_SIZE = type.size;
68+
if (minSize < DEF_SIZE) {
69+
minSize = DEF_SIZE;
70+
}
6371
byte[] buffer = _byteBuffers[ix];
64-
if (buffer == null) {
65-
buffer = balloc(type.size);
72+
if (buffer == null || buffer.length < minSize) {
73+
buffer = balloc(minSize);
6674
} else {
6775
_byteBuffers[ix] = null;
6876
}
6977
return buffer;
7078
}
71-
79+
7280
public final void releaseByteBuffer(ByteBufferType type, byte[] buffer)
7381
{
7482
_byteBuffers[type.ordinal()] = buffer;

0 commit comments

Comments
 (0)