Skip to content

Commit 3633676

Browse files
committed
[Java] Generate final classes to improve performance.
1 parent 0fc9263 commit 3633676

13 files changed

+55
-11
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaGenerator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ private void generateGroupDecoderClassDeclaration(
570570
final String className = formatClassName(groupName);
571571

572572
new Formatter(sb).format("\n" +
573-
indent + "public static class %1$s\n" +
573+
indent + "public static final class %1$s\n" +
574574
indent + " implements Iterable<%1$s>, java.util.Iterator<%1$s>\n" +
575575
indent + "{\n" +
576576
indent + " public static final int HEADER_SIZE = %2$d;\n" +
@@ -622,7 +622,7 @@ private void generateGroupEncoderClassDeclaration(
622622
final String className = encoderName(groupName);
623623

624624
new Formatter(sb).format("\n" +
625-
indent + "public static class %1$s\n" +
625+
indent + "public static final class %1$s\n" +
626626
indent + "{\n" +
627627
indent + " public static final int HEADER_SIZE = %2$d;\n" +
628628
indent + " private final %3$s parentMessage;\n" +
@@ -1659,7 +1659,7 @@ private static CharSequence generateDeclaration(
16591659

16601660
generateTypeJavadoc(sb, BASE_INDENT, typeToken);
16611661
sb.append("@SuppressWarnings(\"all\")\n")
1662-
.append("public class ").append(className).append(implementsString).append('\n')
1662+
.append("public final class ").append(className).append(implementsString).append('\n')
16631663
.append("{\n");
16641664

16651665
return sb;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/ByteOrderCodec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,22 @@ public enum ByteOrderCodec
2323
this.value = value;
2424
}
2525

26+
/**
27+
* The raw encoded value in the Java type representation.
28+
*
29+
* @return the raw value encoded.
30+
*/
2631
public short value()
2732
{
2833
return value;
2934
}
3035

36+
/**
37+
* Lookup the enum value representing the value.
38+
*
39+
* @param value encoded to be looked up.
40+
* @return the enum value representing the value.
41+
*/
3142
public static ByteOrderCodec get(final short value)
3243
{
3344
switch (value)

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Frame Header for start of encoding IR
1010
*/
1111
@SuppressWarnings("all")
12-
public class FrameCodecDecoder
12+
public final class FrameCodecDecoder
1313
{
1414
public static final int BLOCK_LENGTH = 12;
1515
public static final int TEMPLATE_ID = 1;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/FrameCodecEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Frame Header for start of encoding IR
1010
*/
1111
@SuppressWarnings("all")
12-
public class FrameCodecEncoder
12+
public final class FrameCodecEncoder
1313
{
1414
public static final int BLOCK_LENGTH = 12;
1515
public static final int TEMPLATE_ID = 1;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/MessageHeaderDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Message identifiers and length of message root
99
*/
1010
@SuppressWarnings("all")
11-
public class MessageHeaderDecoder
11+
public final class MessageHeaderDecoder
1212
{
1313
public static final int SCHEMA_ID = 1;
1414
public static final int SCHEMA_VERSION = 0;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/MessageHeaderEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Message identifiers and length of message root
99
*/
1010
@SuppressWarnings("all")
11-
public class MessageHeaderEncoder
11+
public final class MessageHeaderEncoder
1212
{
1313
public static final int SCHEMA_ID = 1;
1414
public static final int SCHEMA_VERSION = 0;

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/PresenceCodec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ public enum PresenceCodec
2525
this.value = value;
2626
}
2727

28+
/**
29+
* The raw encoded value in the Java type representation.
30+
*
31+
* @return the raw value encoded.
32+
*/
2833
public short value()
2934
{
3035
return value;
3136
}
3237

38+
/**
39+
* Lookup the enum value representing the value.
40+
*
41+
* @param value encoded to be looked up.
42+
* @return the enum value representing the value.
43+
*/
3344
public static PresenceCodec get(final short value)
3445
{
3546
switch (value)

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/PrimitiveTypeCodec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,22 @@ public enum PrimitiveTypeCodec
4343
this.value = value;
4444
}
4545

46+
/**
47+
* The raw encoded value in the Java type representation.
48+
*
49+
* @return the raw value encoded.
50+
*/
4651
public short value()
4752
{
4853
return value;
4954
}
5055

56+
/**
57+
* Lookup the enum value representing the value.
58+
*
59+
* @param value encoded to be looked up.
60+
* @return the enum value representing the value.
61+
*/
5162
public static PrimitiveTypeCodec get(final short value)
5263
{
5364
switch (value)

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/SignalCodec.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,22 @@ public enum SignalCodec
5353
this.value = value;
5454
}
5555

56+
/**
57+
* The raw encoded value in the Java type representation.
58+
*
59+
* @return the raw value encoded.
60+
*/
5661
public short value()
5762
{
5863
return value;
5964
}
6065

66+
/**
67+
* Lookup the enum value representing the value.
68+
*
69+
* @param value encoded to be looked up.
70+
* @return the enum value representing the value.
71+
*/
6172
public static SignalCodec get(final short value)
6273
{
6374
switch (value)

sbe-tool/src/main/java/uk/co/real_logic/sbe/ir/generated/TokenCodecDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Codec for an IR Token
1010
*/
1111
@SuppressWarnings("all")
12-
public class TokenCodecDecoder
12+
public final class TokenCodecDecoder
1313
{
1414
public static final int BLOCK_LENGTH = 28;
1515
public static final int TEMPLATE_ID = 2;

0 commit comments

Comments
 (0)