Skip to content

Commit

Permalink
Fixes #1195: add recycling of passed-in BufferRecycler
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 19, 2024
1 parent 2b6e7a9 commit 9d612de
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2181,12 +2181,24 @@ public RecyclerPool<BufferRecycler> _getRecyclerPool() {
* @return I/O context created
*/
protected IOContext _createContext(ContentReference contentRef, boolean resourceManaged) {
// 21-Mar-2021, tatu: Bit of defensive coding for backwards compatibility
BufferRecycler br;

if (contentRef == null) {
contentRef = ContentReference.unknown();
br = null;
} else {
Object content = contentRef.getRawContent();
// 18-Jan-2024, tatu: [core#1195] Let's see if we can reuse already allocated recycler
// (is the case when SegmentedStringWriter / ByteArrayBuilder passed)
br = (content instanceof BufferRecycler.Gettable)
? ((BufferRecycler.Gettable) content).bufferRecycler()
: null;
}
if (br == null) {
br = _getBufferRecycler();
}
return new IOContext(_streamReadConstraints, _streamWriteConstraints, _errorReportConfiguration,
_getBufferRecycler(), contentRef, resourceManaged);
br, contentRef, resourceManaged);
}

/**
Expand Down

0 comments on commit 9d612de

Please sign in to comment.