Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static int collectDefaults() {
/**
* @since 2.16
*/
protected BufferRecyclerPool _bufferRecyclerPool;
protected BufferRecyclerPool<BufferRecycler> _bufferRecyclerPool;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will probably consider renaming of BufferRecyclerPool as it'll allow recycling other things, but initially leaving name as-is to simplify merging to master.


/**
* Object that implements conversion functionality between
Expand Down Expand Up @@ -368,7 +368,7 @@ public static int collectDefaults() {
public JsonFactory() { this((ObjectCodec) null); }

public JsonFactory(ObjectCodec oc) {
_bufferRecyclerPool = BufferRecyclerPool.defaultPool();
_bufferRecyclerPool = JsonBufferRecyclers.defaultPool();
_objectCodec = oc;
_quoteChar = DEFAULT_QUOTE_CHAR;
_streamReadConstraints = StreamReadConstraints.defaults();
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public String getRootValueSeparator() {
/**********************************************************
*/

public JsonFactory setBufferRecyclerPool(BufferRecyclerPool p) {
public JsonFactory setBufferRecyclerPool(BufferRecyclerPool<BufferRecycler> p) {
_bufferRecyclerPool = Objects.requireNonNull(p);
return this;
}
Expand Down Expand Up @@ -2150,7 +2150,7 @@ protected JsonGenerator _decorate(JsonGenerator g) {
*/
public BufferRecycler _getBufferRecycler()
{
return _getBufferRecyclerPool().acquireAndLinkBufferRecycler();
return _getBufferRecyclerPool().acquireAndLinkPooled();
}

/**
Expand All @@ -2159,12 +2159,12 @@ public BufferRecycler _getBufferRecycler()
*
* @since 2.16
*/
public BufferRecyclerPool _getBufferRecyclerPool() {
public BufferRecyclerPool<BufferRecycler> _getBufferRecyclerPool() {
// 23-Apr-2015, tatu: Let's allow disabling of buffer recycling
// scheme, for cases where it is considered harmful (possibly
// on Android, for example)
if (!Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING.enabledIn(_factoryFeatures)) {
return BufferRecyclerPool.nonRecyclingPool();
return JsonBufferRecyclers.nonRecyclingPool();
}
return _bufferRecyclerPool;
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/fasterxml/jackson/core/TSFBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.fasterxml.jackson.core.io.OutputDecorator;
import com.fasterxml.jackson.core.json.JsonReadFeature;
import com.fasterxml.jackson.core.json.JsonWriteFeature;
import com.fasterxml.jackson.core.util.BufferRecycler;
import com.fasterxml.jackson.core.util.BufferRecyclerPool;
import com.fasterxml.jackson.core.util.JsonBufferRecyclers;
import com.fasterxml.jackson.core.util.JsonGeneratorDecorator;

/**
Expand Down Expand Up @@ -74,7 +76,7 @@ public abstract class TSFBuilder<F extends JsonFactory,
/**
* @since 2.16
*/
protected BufferRecyclerPool _bufferRecyclerPool;
protected BufferRecyclerPool<BufferRecycler> _bufferRecyclerPool;

/**
* Optional helper object that may decorate input sources, to do
Expand Down Expand Up @@ -141,7 +143,7 @@ protected TSFBuilder(JsonFactory base)
protected TSFBuilder(int factoryFeatures,
int parserFeatures, int generatorFeatures)
{
_bufferRecyclerPool = BufferRecyclerPool.defaultPool();
_bufferRecyclerPool = JsonBufferRecyclers.defaultPool();

_factoryFeatures = factoryFeatures;
_streamReadFeatures = parserFeatures;
Expand Down Expand Up @@ -169,7 +171,7 @@ protected static <T> List<T> _copy(List<T> src) {
public int streamReadFeatures() { return _streamReadFeatures; }
public int streamWriteFeatures() { return _streamWriteFeatures; }

public BufferRecyclerPool bufferRecyclerPool() {
public BufferRecyclerPool<BufferRecycler> bufferRecyclerPool() {
return _bufferRecyclerPool;
}

Expand Down Expand Up @@ -321,7 +323,7 @@ public B configure(JsonWriteFeature f, boolean state) {
*
* @since 2.16
*/
public B bufferRecyclerPool(BufferRecyclerPool p) {
public B bufferRecyclerPool(BufferRecyclerPool<BufferRecycler> p) {
_bufferRecyclerPool = Objects.requireNonNull(p);
return _this();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Rewritten in 2.16 to work with {@link BufferRecyclerPool} abstraction.
*/
public class BufferRecycler
implements BufferRecyclerPool.WithPool<BufferRecycler>
{
/**
* Buffer used for reading byte-based input.
Expand Down Expand Up @@ -86,7 +87,7 @@ public class BufferRecycler
// Note: changed from simple array in 2.10:
protected final AtomicReferenceArray<char[]> _charBuffers;

private BufferRecyclerPool _pool;
private BufferRecyclerPool<BufferRecycler> _pool;

/*
/**********************************************************
Expand Down Expand Up @@ -202,7 +203,8 @@ protected int charBufferLength(int ix) {
*
* @since 2.16
*/
BufferRecycler withPool(BufferRecyclerPool pool) {
@Override
public BufferRecycler withPool(BufferRecyclerPool<BufferRecycler> pool) {
if (this._pool != null) {
throw new IllegalStateException("BufferRecycler already linked to pool: "+pool);
}
Expand All @@ -220,11 +222,11 @@ BufferRecycler withPool(BufferRecyclerPool pool) {
*/
public void release() {
if (_pool != null) {
BufferRecyclerPool tmpPool = _pool;
BufferRecyclerPool<BufferRecycler> tmpPool = _pool;
// nullify the reference to the pool in order to avoid the risk of releasing
// the same BufferRecycler more than once, thus compromising the pool integrity
_pool = null;
tmpPool.releaseBufferRecycler(this);
tmpPool.releasePooled(this);
}
}
}
Loading