Skip to content

Commit

Permalink
Minor prep work for #946
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 8, 2023
1 parent f511bcd commit 3a1eb08
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
3 changes: 0 additions & 3 deletions src/main/java/com/fasterxml/jackson/core/JsonFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,6 @@ public static int collectDefaults() {
/**
* Alternative to the basic symbol table, some stream-based
* parsers use different name canonicalization method.
*<p>
* TODO: should clean up this; looks messy having 2 alternatives
* with not very clear differences.
*
* @since 2.6
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ public final class ByteQuadsCanonicalizer
*/

/**
* Whether canonical symbol Strings are to be intern()ed before added
* to the table or not.
*<p>
* NOTE: non-final to allow disabling intern()ing in case of excessive
* collisions.
* Entity that knows how to {@code intern} Strings, if needed,
* or {@code null} if no interning is wanted.
*
* @since 2.16
*/
protected final boolean _intern;
protected final InternCache _interner;

/**
* Flag that indicates whether we should throw an exception if enough
Expand Down Expand Up @@ -233,7 +232,7 @@ private ByteQuadsCanonicalizer(int sz, int seed)
// and mark as shared just in case to prevent modifications
_hashShared = true;
_seed = seed;
_intern = false;
_interner = null;
_failOnDoS = true;
// Sanity check: let's now allow hash sizes below certain minimum value
if (sz < MIN_HASH_SIZE) {
Expand Down Expand Up @@ -261,7 +260,7 @@ private ByteQuadsCanonicalizer(ByteQuadsCanonicalizer parent, int seed,
{
_parent = parent;
_seed = seed;
_intern = intern;
_interner = intern ? InternCache.instance : null;
_failOnDoS = failOnDoS;
_tableInfo = null; // not used by child tables

Expand Down Expand Up @@ -295,7 +294,7 @@ private ByteQuadsCanonicalizer(TableInfo state)
{
_parent = null;
_seed = 0;
_intern = false;
_interner = null;
_failOnDoS = true;
_tableInfo = null; // not used by child tables

Expand Down Expand Up @@ -872,8 +871,8 @@ private boolean _verifyLongName2(int[] q, int qlen, int spillOffset)
*/
public String addName(String name, int q1) throws StreamConstraintsException {
_verifySharing();
if (_intern) {
name = InternCache.instance.intern(name);
if (_interner != null) {
name = _interner.intern(name);
}
int offset = _findOffsetForAdd(calcHash(q1));
_hashArea[offset] = q1;
Expand All @@ -892,8 +891,8 @@ public String addName(String name, int q1) throws StreamConstraintsException {
*/
public String addName(String name, int q1, int q2) throws StreamConstraintsException {
_verifySharing();
if (_intern) {
name = InternCache.instance.intern(name);
if (_interner != null) {
name = _interner.intern(name);
}

// 20-Mar-2021, tatu: For some reason, pre-2.13 there was logic
Expand All @@ -920,8 +919,8 @@ public String addName(String name, int q1, int q2) throws StreamConstraintsExcep
*/
public String addName(String name, int q1, int q2, int q3) throws StreamConstraintsException {
_verifySharing();
if (_intern) {
name = InternCache.instance.intern(name);
if (_interner != null) {
name = _interner.intern(name);
}
int offset = _findOffsetForAdd(calcHash(q1, q2, q3));
_hashArea[offset] = q1;
Expand All @@ -943,8 +942,8 @@ public String addName(String name, int q1, int q2, int q3) throws StreamConstrai
public String addName(String name, int[] q, int qlen) throws StreamConstraintsException
{
_verifySharing();
if (_intern) {
name = InternCache.instance.intern(name);
if (_interner != null) {
name = _interner.intern(name);
}
int offset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public final class InternCache
*/
private final Object lock = new Object();

private InternCache() { super(MAX_ENTRIES, 0.8f, 4); }
public InternCache() { this(MAX_ENTRIES, 0.8f, 4); }

public InternCache(int maxSize, float loadFactor, int concurrency) {
super(maxSize, loadFactor, concurrency);
}

public String intern(String input) {
String result = get(input);
Expand Down

0 comments on commit 3a1eb08

Please sign in to comment.