From f4302a8531161c8b400d9284947181f3628eb235 Mon Sep 17 00:00:00 2001 From: Andrew Ford Date: Thu, 24 Aug 2017 21:22:59 -0400 Subject: [PATCH 1/4] Remove inefficiencies created by introducing specific C++11 functionality --- .../src/main/cpp/SbeCarCodecBench.h | 3 ++ .../sbe/generation/cpp/CppGenerator.java | 37 +------------------ 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/sbe-benchmarks/src/main/cpp/SbeCarCodecBench.h b/sbe-benchmarks/src/main/cpp/SbeCarCodecBench.h index c3b1d60804..ef5930a009 100644 --- a/sbe-benchmarks/src/main/cpp/SbeCarCodecBench.h +++ b/sbe-benchmarks/src/main/cpp/SbeCarCodecBench.h @@ -83,6 +83,8 @@ class SbeCarCodecBench : public CodecBench { car.wrapForDecode((char *)buffer, 0, Car::sbeBlockLength(), Car::sbeSchemaVersion(), bufferLength); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" int64_t tmpInt; const char *tmpChar; double tmpDouble; @@ -132,6 +134,7 @@ class SbeCarCodecBench : public CodecBench tmpChar = car.manufacturer(); tmpChar = car.model(); +#pragma GCC diagnostic pop return car.encodedLength(); }; diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index b08f5f56b1..857603bbd8 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -294,23 +294,13 @@ private static void generateGroupClassHeader( dimensionHeaderLength, blockLength, formatClassName(groupName))); sb.append( - indent + "#if __cplusplus < 201103L\n" + - indent + " template inline void forEach(Func& func)\n" + + indent + " template inline void forEach(Func func)\n" + indent + " {\n" + indent + " while (hasNext())\n" + indent + " {\n" + indent + " next(); func(*this);\n" + indent + " }\n" + - indent + " }\n\n" + - indent + "#else\n" + - indent + " template inline void forEach(Func&& func)\n" + - indent + " {\n" + - indent + " while (hasNext())\n" + - indent + " {\n" + - indent + " next(); func(*this);\n" + - indent + " }\n" + - indent + " }\n\n" + - indent + "#endif\n\n"); + indent + " }\n\n"); } private static CharSequence generateGroupProperty( @@ -1262,18 +1252,6 @@ private static CharSequence generateFixedFlyweightCode(final String className, f " }\n\n" + " %1$s(const %1$s& codec) :\n" + " m_buffer(codec.m_buffer), m_offset(codec.m_offset), m_actingVersion(codec.m_actingVersion){}\n\n" + - "#if __cplusplus >= 201103L\n" + - " %1$s(%1$s&& codec) :\n" + - " m_buffer(codec.m_buffer), m_offset(codec.m_offset), m_actingVersion(codec.m_actingVersion){}\n\n" + - " %1$s& operator=(%1$s&& codec) SBE_NOEXCEPT\n" + - " {\n" + - " m_buffer = codec.m_buffer;\n" + - " m_bufferLength = codec.m_bufferLength;\n" + - " m_offset = codec.m_offset;\n" + - " m_actingVersion = codec.m_actingVersion;\n" + - " return *this;\n" + - " }\n\n" + - "#endif\n\n" + " %1$s& operator=(const %1$s& codec) SBE_NOEXCEPT\n" + " {\n" + " m_buffer = codec.m_buffer;\n" + @@ -1325,17 +1303,6 @@ private static CharSequence generateConstructorsAndOperators(final String classN " {\n" + " reset(codec);\n" + " }\n\n" + - "#if __cplusplus >= 201103L\n" + - " %1$s(%1$s&& codec)\n" + - " {\n" + - " reset(codec);\n" + - " }\n\n" + - " %1$s& operator=(%1$s&& codec)\n" + - " {\n" + - " reset(codec);\n" + - " return *this;\n" + - " }\n\n" + - "#endif\n\n" + " %1$s& operator=(const %1$s& codec)\n" + " {\n" + " reset(codec);\n" + From 49e240e471b7bde00d460a09d122260816fc653f Mon Sep 17 00:00:00 2001 From: Andrew Ford Date: Fri, 25 Aug 2017 17:45:55 -0400 Subject: [PATCH 2/4] Add rvalue-reference handling of forEach --- .../real_logic/sbe/generation/cpp/CppGenerator.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 857603bbd8..9e8f6c6685 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -294,13 +294,22 @@ private static void generateGroupClassHeader( dimensionHeaderLength, blockLength, formatClassName(groupName))); sb.append( - indent + " template inline void forEach(Func func)\n" + + indent + " template inline void forEach(Func& func)\n" + indent + " {\n" + indent + " while (hasNext())\n" + indent + " {\n" + indent + " next(); func(*this);\n" + indent + " }\n" + - indent + " }\n\n"); + indent + " }\n" + + indent + "#if __cplusplus >= 201103L\n" + + indent + " template inline void forEach(Func&& func)\n" + + indent + " {\n" + + indent + " while (hasNext())\n" + + indent + " {\n" + + indent + " next(); func(*this);\n" + + indent + " }\n" + + indent + " }\n" + + indent + "#endif\n\n } private static CharSequence generateGroupProperty( From 993aa6251242c9790f15797f4769b0a0520e8df9 Mon Sep 17 00:00:00 2001 From: Andrew Ford Date: Mon, 25 Sep 2017 11:28:46 -0400 Subject: [PATCH 3/4] Add move constructor and assignment operator for C++11 generated code --- .../sbe/generation/cpp/CppGenerator.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 9e8f6c6685..a0ad1d7b30 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -309,7 +309,14 @@ private static void generateGroupClassHeader( indent + " next(); func(*this);\n" + indent + " }\n" + indent + " }\n" + - indent + "#endif\n\n + indent + " template inline void forEach(Func const& func)\n" + + indent + " {\n" + + indent + " while (hasNext())\n" + + indent + " {\n" + + indent + " next(); func(*this);\n" + + indent + " }\n" + + indent + " }\n" + + indent + "#endif\n\n"); } private static CharSequence generateGroupProperty( @@ -1316,7 +1323,23 @@ private static CharSequence generateConstructorsAndOperators(final String classN " {\n" + " reset(codec);\n" + " return *this;\n" + - " }\n\n", + " }\n\n" + + "#if __cplusplus >= 201103L\n" + + " %1$s(%1$s&& codec) : \n" + + " {\n" + + " reset(codec);\n" + + " codec.reset(%1$s());\n" + + " }\n\n" + + " %1$s& operator =(%1$s&& codec) : \n" + + " {\n" + + " if (this != &codec)\n" + + " {\n" + + " reset(codec);\n" + + " codec.reset(%1$s());\n" + + " }\n" + + " return *this;\n" + + " }\n" + + "#endif\n\n", className); } From 523ebeb65bc1803f3de9b9afa5982ab02e84b976 Mon Sep 17 00:00:00 2001 From: Andrew Ford Date: Mon, 25 Sep 2017 12:02:19 -0400 Subject: [PATCH 4/4] Remove tabs and change to spaces (stupid default editor settings) --- .../uk/co/real_logic/sbe/generation/cpp/CppGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java index 9f2234ab72..be9d15d492 100755 --- a/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java +++ b/sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java @@ -1296,9 +1296,9 @@ private static CharSequence generateFixedFlyweightCode(final String className, f " m_bufferLength(codec.m_bufferLength),\n" + " m_offset(codec.m_offset),\n" + " m_actingVersion(codec.m_actingVersion)\n" + - " {\n" + - " codec.reset(%1$s())\n" + - " }\n\n" + + " {\n" + + " codec.reset(%1$s())\n" + + " }\n\n" + " %1$s& operator=(%1$s&& codec) SBE_NOEXCEPT\n" + " {\n" + " if (this != &codec);\n" +