Skip to content

Commit e78fc1f

Browse files
committed
minor improvement to text buffer allocation
1 parent 007dccb commit e78fc1f

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
*/
1111
public class BufferRecycler
1212
{
13-
// public final static int DEFAULT_WRITE_CONCAT_BUFFER_LEN = 2000;
14-
1513
/**
1614
* Buffer used for reading byte-based input.
1715
*/

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,16 @@ public char[] finishCurrentSegment() {
558558
_segments.add(_currentSegment);
559559
int oldLen = _currentSegment.length;
560560
_segmentSize += oldLen;
561+
_currentSize = 0;
562+
561563
// Let's grow segments by 50%
562-
int newLen = Math.min(oldLen + (oldLen >> 1), MAX_SEGMENT_LEN);
564+
int newLen = oldLen + (oldLen >> 1);
565+
if (newLen < MIN_SEGMENT_LEN) {
566+
newLen = MIN_SEGMENT_LEN;
567+
} else if (newLen > MAX_SEGMENT_LEN) {
568+
newLen = MAX_SEGMENT_LEN;
569+
}
563570
char[] curr = carr(newLen);
564-
_currentSize = 0;
565571
_currentSegment = curr;
566572
return curr;
567573
}
@@ -655,14 +661,17 @@ private void expand(int minNewSegmentSize)
655661
_hasSegments = true;
656662
_segments.add(curr);
657663
_segmentSize += curr.length;
664+
_currentSize = 0;
658665
int oldLen = curr.length;
666+
659667
// Let's grow segments by 50% minimum
660-
int sizeAddition = oldLen >> 1;
661-
if (sizeAddition < minNewSegmentSize) {
662-
sizeAddition = minNewSegmentSize;
668+
int newLen = oldLen + (oldLen >> 1);
669+
if (newLen < MIN_SEGMENT_LEN) {
670+
newLen = MIN_SEGMENT_LEN;
671+
} else if (newLen > MAX_SEGMENT_LEN) {
672+
newLen = MAX_SEGMENT_LEN;
663673
}
664-
_currentSize = 0;
665-
_currentSegment = carr(Math.min(MAX_SEGMENT_LEN, oldLen + sizeAddition));
674+
_currentSegment = carr(newLen);
666675
}
667676

668677
private char[] resultArray()

0 commit comments

Comments
 (0)