Skip to content

Commit

Permalink
[C++] hide the m_codecStatePtr behind ifdefs to avoid overhead when p…
Browse files Browse the repository at this point in the history
…recedence checking is disabled (#1036)
  • Loading branch information
nbradac authored Dec 13, 2024
1 parent bcb2e06 commit 3199ae7
Showing 1 changed file with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -694,6 +694,7 @@ private void generateGroupClassHeader(

if (null != fieldPrecedenceModel)
{
sb.append("#if defined(").append(precedenceChecksFlagName).append(")\n");
new Formatter(sb).format(
indent + " CodecState *m_codecStatePtr = nullptr;\n\n" +

@@ -710,19 +711,38 @@ private void generateGroupClassHeader(
indent + " void codecState(CodecState codecState)\n" +
indent + " {\n" +
indent + " *m_codecStatePtr = codecState;\n" +
indent + " }\n\n"
indent + " }\n"
);
sb.append("#else\n");
new Formatter(sb).format(
indent + " CodecState codecState() const SBE_NOEXCEPT\n" +
indent + " {\n" +
indent + " return " + qualifiedStateCase(fieldPrecedenceModel.notWrappedState()) + ";\n" +
indent + " }\n\n" +

indent + " CodecState *codecStatePtr()\n" +
indent + " {\n" +
indent + " return nullptr;\n" +
indent + " }\n\n" +

indent + " void codecState(CodecState codecState)\n" +
indent + " {\n" +
indent + " }\n"
);
sb.append("#endif\n\n");
}

sb.append(generateHiddenCopyConstructor(indent + " ", groupClassName));

final String codecStateParameter = null == fieldPrecedenceModel ?
")\n" :
",\n " + indent + " CodecState *codecState)\n";
",\n" + indent + " CodecState *codecState)\n";

final String codecStateAssignment = null == fieldPrecedenceModel ?
"" :
indent + " m_codecStatePtr = codecState;\n";
"#if defined(" + precedenceChecksFlagName + ")\n" +
indent + " m_codecStatePtr = codecState;\n" +
"#endif\n";

new Formatter(sb).format(
indent + "public:\n" +
@@ -802,7 +822,9 @@ private void generateGroupClassHeader(
{
final String codecStateNullAssignment = null == fieldPrecedenceModel ?
"" :
indent + " m_codecStatePtr = nullptr;\n";
"#if defined(" + precedenceChecksFlagName + ")\n" +
indent + " m_codecStatePtr = nullptr;\n" +
"#endif\n";

new Formatter(sb).format(
indent + " inline void notPresent(std::uint64_t actingVersion)\n" +

0 comments on commit 3199ae7

Please sign in to comment.