Skip to content

Commit 1e27b2a

Browse files
committed
further cleanup for cbor/smile output context handlign
1 parent 04be073 commit 1e27b2a

File tree

4 files changed

+15
-49
lines changed

4 files changed

+15
-49
lines changed

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ protected void maybeCopyTag(JsonParser p) throws IOException {
530530
@Override
531531
public final void writeStartArray() throws IOException {
532532
_verifyValueWrite("start an array");
533-
_cborContext = _cborContext.createChildArrayContext();
533+
_cborContext = _cborContext.createChildArrayContext(null);
534534
if (_elementCountsPtr > 0) {
535535
_pushRemainingElements();
536536
}
@@ -546,7 +546,7 @@ public final void writeStartArray() throws IOException {
546546
@Override
547547
public void writeStartArray(int elementsToWrite) throws IOException {
548548
_verifyValueWrite("start an array");
549-
_cborContext = _cborContext.createChildArrayContext();
549+
_cborContext = _cborContext.createChildArrayContext(null);
550550
_pushRemainingElements();
551551
_currentRemainingElements = elementsToWrite;
552552
_writeLengthMarker(PREFIX_TYPE_ARRAY, elementsToWrite);

cbor/src/main/java/com/fasterxml/jackson/dataformat/cbor/CBORWriteContext.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,6 @@ public final class CBORWriteContext extends JsonStreamContext
6060
/**********************************************************
6161
*/
6262

63-
protected CBORWriteContext(int type, CBORWriteContext parent, DupDetector dups) {
64-
super();
65-
_type = type;
66-
_parent = parent;
67-
_dups = dups;
68-
_index = -1;
69-
}
70-
7163
protected CBORWriteContext(int type, CBORWriteContext parent, DupDetector dups,
7264
Object currentValue) {
7365
super();
@@ -78,16 +70,6 @@ protected CBORWriteContext(int type, CBORWriteContext parent, DupDetector dups,
7870
_currentValue = currentValue;
7971
}
8072

81-
private CBORWriteContext reset(int type) {
82-
_type = type;
83-
_index = -1;
84-
// as long as _gotFieldId false, current name/id can be left as-is
85-
_gotFieldId = false;
86-
_currentValue = null;
87-
if (_dups != null) { _dups.reset(); }
88-
return this;
89-
}
90-
9173
private CBORWriteContext reset(int type, Object currentValue) {
9274
_type = type;
9375
_index = -1;
@@ -120,16 +102,17 @@ public void setCurrentValue(Object v) {
120102
*/
121103

122104
public static CBORWriteContext createRootContext(DupDetector dd) {
123-
return new CBORWriteContext(TYPE_ROOT, null, dd);
105+
return new CBORWriteContext(TYPE_ROOT, null, dd, null);
124106
}
125107

126-
public CBORWriteContext createChildArrayContext() {
108+
public CBORWriteContext createChildArrayContext(Object currentValue) {
127109
CBORWriteContext ctxt = _childToRecycle;
128110
if (ctxt == null) {
129-
_childToRecycle = ctxt = new CBORWriteContext(TYPE_ARRAY, this, (_dups == null) ? null : _dups.child());
111+
_childToRecycle = ctxt = new CBORWriteContext(TYPE_ARRAY, this,
112+
(_dups == null) ? null : _dups.child(), currentValue);
130113
return ctxt;
131114
}
132-
return ctxt.reset(TYPE_ARRAY);
115+
return ctxt.reset(TYPE_ARRAY, currentValue);
133116
}
134117

135118
public CBORWriteContext createChildObjectContext(Object currentValue) {

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ public void writeBytes(byte[] data, int offset, int len) throws IOException
604604
public final void writeStartArray() throws IOException
605605
{
606606
_verifyValueWrite("start an array");
607-
_smileContext = _smileContext.createChildArrayContext();
607+
_smileContext = _smileContext.createChildArrayContext(null);
608608
_writeByte(TOKEN_LITERAL_START_ARRAY);
609609
}
610610

611-
@Override // defined since 2.6.3
611+
@Override
612612
public final void writeStartArray(int size) throws IOException
613613
{
614614
_verifyValueWrite("start an array");
615-
_smileContext = _smileContext.createChildArrayContext();
615+
_smileContext = _smileContext.createChildArrayContext(null);
616616
_writeByte(TOKEN_LITERAL_START_ARRAY);
617617
}
618618

smile/src/main/java/com/fasterxml/jackson/dataformat/smile/SmileWriteContext.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ public final class SmileWriteContext extends JsonStreamContext
5656
/**********************************************************
5757
*/
5858

59-
protected SmileWriteContext(int type, SmileWriteContext parent, DupDetector dups) {
60-
super();
61-
_type = type;
62-
_parent = parent;
63-
_dups = dups;
64-
_index = -1;
65-
}
66-
6759
protected SmileWriteContext(int type, SmileWriteContext parent, DupDetector dups,
6860
Object currentValue) {
6961
super();
@@ -74,16 +66,6 @@ protected SmileWriteContext(int type, SmileWriteContext parent, DupDetector dups
7466
_currentValue = currentValue;
7567
}
7668

77-
private SmileWriteContext reset(int type) {
78-
_type = type;
79-
_index = -1;
80-
// as long as _gotFieldId false, current name/id can be left as-is
81-
_gotFieldId = false;
82-
_currentValue = null;
83-
if (_dups != null) { _dups.reset(); }
84-
return this;
85-
}
86-
8769
private SmileWriteContext reset(int type, Object currentValue) {
8870
_type = type;
8971
_index = -1;
@@ -116,16 +98,17 @@ public void setCurrentValue(Object v) {
11698
*/
11799

118100
public static SmileWriteContext createRootContext(DupDetector dd) {
119-
return new SmileWriteContext(TYPE_ROOT, null, dd);
101+
return new SmileWriteContext(TYPE_ROOT, null, dd, null);
120102
}
121103

122-
public SmileWriteContext createChildArrayContext() {
104+
public SmileWriteContext createChildArrayContext(Object currentValue) {
123105
SmileWriteContext ctxt = _childToRecycle;
124106
if (ctxt == null) {
125-
_childToRecycle = ctxt = new SmileWriteContext(TYPE_ARRAY, this, (_dups == null) ? null : _dups.child());
107+
_childToRecycle = ctxt = new SmileWriteContext(TYPE_ARRAY, this,
108+
(_dups == null) ? null : _dups.child(), currentValue);
126109
return ctxt;
127110
}
128-
return ctxt.reset(TYPE_ARRAY);
111+
return ctxt.reset(TYPE_ARRAY, currentValue);
129112
}
130113

131114
public SmileWriteContext createChildObjectContext(Object currentValue) {

0 commit comments

Comments
 (0)