Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] hide the m_codecStatePtr behind ifdefs to avoid overhead when p… #1036

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" +

Expand All @@ -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" +
Expand Down Expand Up @@ -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" +
Expand Down
Loading