Skip to content

Commit

Permalink
Fix #79 (non-working minor optimization)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 4, 2021
1 parent fcee651 commit a87f01c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class ValueWriterLocator extends ValueLocatorBase
/**
* Reusable lookup key; only used by per-thread instances.
*/
private ClassKey _key;
private final ClassKey _key;

private Class<?> _prevClass;

Expand All @@ -97,17 +97,21 @@ protected ValueWriterLocator(int features,
_writeContext = null;
_writerProvider = rwp;
_writerModifier = rwm;
// should not be needed for blueprint instance
_key = null;
}

// for per-call instances
protected ValueWriterLocator(ValueWriterLocator base,
int features, JSONWriter w) {
int features, JSONWriter w)
{
_features = features;
_writeContext = w;
_knownSerTypes = base._knownSerTypes;
_knownWriters = base._knownWriters;
_writerProvider = base._writerProvider;
_writerModifier = base._writerModifier;
_key = new ClassKey();
}

public final static ValueWriterLocator blueprint(ReaderWriterProvider rwp, ReaderWriterModifier rwm) {
Expand Down Expand Up @@ -160,9 +164,8 @@ public final int findSerializationType(Class<?> raw)
if (raw == String.class && (_writerModifier == null)) {
return SER_STRING;
}
ClassKey k = (_key == null) ? new ClassKey(raw, _features) : _key.with(raw, _features);
final ClassKey k = _key.with(raw, _features);
int type;

Integer I = _knownSerTypes.get(k);

if (I == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public void setValue(Long v) {
*/

public void testBasicTypeDetectionForSer() {
ValueWriterLocator td = ValueWriterLocator.blueprint(null, null);
// note: must create non-blue-print instance to avoid NPE
ValueWriterLocator td = ValueWriterLocator.blueprint(null, null)
.perOperationInstance(null, 0);
assertEquals(ValueWriterLocator.SER_STRING, td.findSerializationType(String.class));
assertEquals(ValueWriterLocator.SER_CHAR_ARRAY, td.findSerializationType(char[].class));
assertEquals(ValueWriterLocator.SER_INT_ARRAY, td.findSerializationType(int[].class));
Expand Down
2 changes: 1 addition & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Modules:

2.13.0 (not yet released)

No changes since 2.12
#79: Reuse of ClassKey in ValueWriterLocator not working

2.12.2 (03-Mar-2021)

Expand Down

0 comments on commit a87f01c

Please sign in to comment.