-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor refactoring wrt #400 to make it easier to override behavior
- Loading branch information
1 parent
3756448
commit e0780ca
Showing
7 changed files
with
87 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/fasterxml/jackson/core/util/BufferRecyclers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.fasterxml.jackson.core.util; | ||
|
||
import java.lang.ref.SoftReference; | ||
|
||
import com.fasterxml.jackson.core.io.JsonStringEncoder; | ||
|
||
/** | ||
* Helper entity used to further | ||
* | ||
* @since 2.9.2 | ||
*/ | ||
public class BufferRecyclers | ||
{ | ||
/* | ||
/********************************************************** | ||
/* BufferRecyclers for parsers, generators | ||
/********************************************************** | ||
*/ | ||
|
||
/** | ||
* This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference} | ||
* to a {@link BufferRecycler} used to provide a low-cost | ||
* buffer recycling between reader and writer instances. | ||
*/ | ||
final protected static ThreadLocal<SoftReference<BufferRecycler>> _recyclerRef | ||
= new ThreadLocal<SoftReference<BufferRecycler>>(); | ||
|
||
public static BufferRecycler getBufferRecycler() | ||
{ | ||
SoftReference<BufferRecycler> ref = _recyclerRef.get(); | ||
BufferRecycler br = (ref == null) ? null : ref.get(); | ||
|
||
if (br == null) { | ||
br = new BufferRecycler(); | ||
_recyclerRef.set(new SoftReference<BufferRecycler>(br)); | ||
} | ||
return br; | ||
} | ||
|
||
/* | ||
/********************************************************** | ||
/* JsonStringEncoder | ||
/********************************************************** | ||
*/ | ||
|
||
/** | ||
* This <code>ThreadLocal</code> contains a {@link java.lang.ref.SoftReference} | ||
* to a {@link BufferRecycler} used to provide a low-cost | ||
* buffer recycling between reader and writer instances. | ||
*/ | ||
final protected static ThreadLocal<SoftReference<JsonStringEncoder>> _encoderRef | ||
= new ThreadLocal<SoftReference<JsonStringEncoder>>(); | ||
|
||
public static JsonStringEncoder getJsonStringEncoder() { | ||
SoftReference<JsonStringEncoder> ref = _encoderRef.get(); | ||
JsonStringEncoder enc = (ref == null) ? null : ref.get(); | ||
|
||
if (enc == null) { | ||
enc = new JsonStringEncoder(); | ||
_encoderRef.set(new SoftReference<JsonStringEncoder>(enc)); | ||
} | ||
return enc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/test/java/com/fasterxml/jackson/core/util/TestTextBuffer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters