Skip to content

Commit 4a2e588

Browse files
committed
HY-73 issue #532: bugfix when resetting groups decoder, then old group references were being nullified which caused unecessary allocation on new decodings
1 parent edb557a commit 4a2e588

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

artio-codecs/src/main/java/uk/co/real_logic/artio/dictionary/generation/DecoderGenerator.java

+14-13
Original file line numberDiff line numberDiff line change
@@ -416,28 +416,21 @@ protected String resetGroup(final Entry entry)
416416
" {\n" +
417417
" for (final %2$s %6$s : %5$s.iterator())\n" +
418418
" {\n" +
419+
" %6$s.reset();\n" +
419420
" if (%6$s.next() == null)\n" +
420421
" {\n" +
421-
" %6$s.reset();\n" +
422422
" break;\n" +
423423
" }\n" +
424-
" else\n" +
425-
" {\n" +
426-
" %6$s.reset();\n" +
427-
" }\n" +
428424
" }\n" +
429425
" %3$s = MISSING_INT;\n" +
430426
" has%4$s = false;\n" +
431-
" %7$s = null;\n" +
432427
" }\n\n",
433428
resetMethod,
434429
decoderClassName(name),
435430
formatPropertyName(numberField.name()),
436431
numberField.name(),
437432
iteratorFieldName(group),
438-
formatPropertyName(decoderClassName(name)),
439-
formatPropertyName(name)
440-
);
433+
formatPropertyName(decoderClassName(name)));
441434
}
442435
}
443436

@@ -491,9 +484,6 @@ private String additionalReset(final boolean isGroup)
491484
{
492485
return
493486
" buffer = null;\n" +
494-
(isGroup ?
495-
" next = null;\n" : ""
496-
) +
497487
" if (" + CODEC_VALIDATION_ENABLED + ")\n" +
498488
" {\n" +
499489
" invalidTagId = Decoder.NO_ERROR;\n" +
@@ -1743,6 +1733,7 @@ private String generateDecodePrefix(
17431733
" this.buffer = buffer;\n" +
17441734
" final int end = offset + length;\n" +
17451735
" int position = offset;\n" +
1736+
" int positionIter = position;\n" +
17461737
(hasCommonCompounds ? " position += header.decode(buffer, position, length);\n" : "") +
17471738
(isGroup ? " seenFields.clear();\n" : "") +
17481739
" int tag;\n\n" +
@@ -1921,7 +1912,17 @@ private String decodeGroup(final Entry entry)
19211912
" {\n" +
19221913
" if (%1$sCurrent != null)\n" +
19231914
" {\n" +
1924-
" position += %1$sCurrent.decode(buffer, position, end - position);\n" +
1915+
" positionIter = %1$sCurrent.decode(buffer, position, end - position);\n" +
1916+
" if (positionIter == 0 && " + CODEC_VALIDATION_ENABLED + ")\n" +
1917+
" {\n" +
1918+
" invalidTagId = tag;\n" +
1919+
" rejectReason = " + INCORRECT_NUMINGROUP_COUNT_FOR_REPEATING_GROUP + ";\n" +
1920+
" break;\n" +
1921+
" }\n" +
1922+
" else\n" +
1923+
" {\n" +
1924+
" position += positionIter;\n" +
1925+
" }\n" +
19251926
" %1$sCurrent = %1$sCurrent.next();\n" +
19261927
" }\n" +
19271928
" }\n" +

artio-codecs/src/test/java/uk/co/real_logic/artio/dictionary/generation/AbstractDecoderGeneratorTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1179,10 +1179,14 @@ public void shouldResetAllNestedRepeatingGroupEntries() throws Exception
11791179
assertEquals(2, getNoEgGroupGroupCounter(decoder));
11801180

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

11841188
group = next(group);
1185-
assertNull(getNestedGroup(group));
1189+
assertNotNull(getNestedGroup(group));
11861190
}
11871191

11881192
@Test

0 commit comments

Comments
 (0)