Skip to content

Commit

Permalink
HY-73 issue #532: bugfix when resetting groups decoder, then old grou…
Browse files Browse the repository at this point in the history
…p references were being nullified which caused unecessary allocation on new decodings
  • Loading branch information
lucianoviana committed Dec 10, 2024
1 parent edb557a commit 712699c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,28 +416,21 @@ protected String resetGroup(final Entry entry)
" {\n" +
" for (final %2$s %6$s : %5$s.iterator())\n" +
" {\n" +
" %6$s.reset();\n" +
" if (%6$s.next() == null)\n" +
" {\n" +
" %6$s.reset();\n" +
" break;\n" +
" }\n" +
" else\n" +
" {\n" +
" %6$s.reset();\n" +
" }\n" +
" }\n" +
" %3$s = MISSING_INT;\n" +
" has%4$s = false;\n" +
" %7$s = null;\n" +
" }\n\n",
resetMethod,
decoderClassName(name),
formatPropertyName(numberField.name()),
numberField.name(),
iteratorFieldName(group),
formatPropertyName(decoderClassName(name)),
formatPropertyName(name)
);
formatPropertyName(decoderClassName(name)));
}
}

Expand Down Expand Up @@ -491,9 +484,6 @@ private String additionalReset(final boolean isGroup)
{
return
" buffer = null;\n" +
(isGroup ?
" next = null;\n" : ""
) +
" if (" + CODEC_VALIDATION_ENABLED + ")\n" +
" {\n" +
" invalidTagId = Decoder.NO_ERROR;\n" +
Expand Down Expand Up @@ -1743,6 +1733,7 @@ private String generateDecodePrefix(
" this.buffer = buffer;\n" +
" final int end = offset + length;\n" +
" int position = offset;\n" +
" int positionIter = position;\n" +
(hasCommonCompounds ? " position += header.decode(buffer, position, length);\n" : "") +
(isGroup ? " seenFields.clear();\n" : "") +
" int tag;\n\n" +
Expand Down Expand Up @@ -1921,7 +1912,17 @@ private String decodeGroup(final Entry entry)
" {\n" +
" if (%1$sCurrent != null)\n" +
" {\n" +
" position += %1$sCurrent.decode(buffer, position, end - position);\n" +
" positionIter = %1$sCurrent.decode(buffer, position, end - position);\n" +
" if (positionIter == 0 && " + CODEC_VALIDATION_ENABLED + ")\n" +
" {\n" +
" invalidTagId = tag;\n" +
" rejectReason = " + INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP + ";\n" +
" break;\n" +
" }\n" +
" else\n" +
" {\n" +
" position += positionIter;\n" +
" }\n" +
" %1$sCurrent = %1$sCurrent.next();\n" +
" }\n" +
" }\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,10 +1179,14 @@ public void shouldResetAllNestedRepeatingGroupEntries() throws Exception
assertEquals(2, getNoEgGroupGroupCounter(decoder));

group = getEgGroup(decoder);
assertNull(getNestedGroup(group));

// Although the message does not have nestedEg tags, the decoders will remain
// This is to ensure allocation is done only when it's necessary to add new elements to a repeating group
// for more details see issue https://github.com/real-logic/artio/issues/532
assertNotNull(getNestedGroup(group));

group = next(group);
assertNull(getNestedGroup(group));
assertNotNull(getNestedGroup(group));
}

@Test
Expand Down

0 comments on commit 712699c

Please sign in to comment.