Skip to content

Commit 66b7742

Browse files
committed
Use LinkedHashMap to keep enum values in order so lookup table can be jump table.
1 parent ef68083 commit 66b7742

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

main/java/uk/co/real_logic/sbe/ir/generated/ByteOrderCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
public enum ByteOrderCodec
77
{
8-
SBE_BIG_ENDIAN((short)1),
98
SBE_LITTLE_ENDIAN((short)0),
9+
SBE_BIG_ENDIAN((short)1),
1010
NULL_VAL((short)255);
1111

1212
private final short value;
@@ -25,8 +25,8 @@ public static ByteOrderCodec get(final short value)
2525
{
2626
switch (value)
2727
{
28-
case 1: return SBE_BIG_ENDIAN;
2928
case 0: return SBE_LITTLE_ENDIAN;
29+
case 1: return SBE_BIG_ENDIAN;
3030
case 255: return NULL_VAL;
3131
}
3232

main/java/uk/co/real_logic/sbe/ir/generated/PresenceCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
public enum PresenceCodec
77
{
8-
CONSTANT((short)2),
98
REQUIRED((short)0),
109
OPTIONAL((short)1),
10+
CONSTANT((short)2),
1111
NULL_VAL((short)255);
1212

1313
private final short value;
@@ -26,9 +26,9 @@ public static PresenceCodec get(final short value)
2626
{
2727
switch (value)
2828
{
29-
case 2: return CONSTANT;
3029
case 0: return REQUIRED;
3130
case 1: return OPTIONAL;
31+
case 2: return CONSTANT;
3232
case 255: return NULL_VAL;
3333
}
3434

main/java/uk/co/real_logic/sbe/ir/generated/PrimitiveTypeCodec.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
public enum PrimitiveTypeCodec
77
{
8-
INT32((short)4),
9-
INT8((short)2),
8+
NONE((short)0),
109
CHAR((short)1),
11-
DOUBLE((short)11),
12-
FLOAT((short)10),
13-
UINT32((short)8),
14-
UINT8((short)6),
10+
INT8((short)2),
11+
INT16((short)3),
12+
INT32((short)4),
1513
INT64((short)5),
16-
UINT64((short)9),
17-
NONE((short)0),
14+
UINT8((short)6),
1815
UINT16((short)7),
19-
INT16((short)3),
16+
UINT32((short)8),
17+
UINT64((short)9),
18+
FLOAT((short)10),
19+
DOUBLE((short)11),
2020
NULL_VAL((short)255);
2121

2222
private final short value;
@@ -35,18 +35,18 @@ public static PrimitiveTypeCodec get(final short value)
3535
{
3636
switch (value)
3737
{
38-
case 4: return INT32;
39-
case 2: return INT8;
38+
case 0: return NONE;
4039
case 1: return CHAR;
41-
case 11: return DOUBLE;
42-
case 10: return FLOAT;
43-
case 8: return UINT32;
44-
case 6: return UINT8;
40+
case 2: return INT8;
41+
case 3: return INT16;
42+
case 4: return INT32;
4543
case 5: return INT64;
46-
case 9: return UINT64;
47-
case 0: return NONE;
44+
case 6: return UINT8;
4845
case 7: return UINT16;
49-
case 3: return INT16;
46+
case 8: return UINT32;
47+
case 9: return UINT64;
48+
case 10: return FLOAT;
49+
case 11: return DOUBLE;
5050
case 255: return NULL_VAL;
5151
}
5252

main/java/uk/co/real_logic/sbe/ir/generated/SignalCodec.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
public enum SignalCodec
77
{
8-
END_SET((short)14),
9-
BEGIN_VAR_DATA((short)15),
8+
BEGIN_MESSAGE((short)1),
109
END_MESSAGE((short)2),
10+
BEGIN_COMPOSITE((short)3),
11+
END_COMPOSITE((short)4),
1112
BEGIN_FIELD((short)5),
1213
END_FIELD((short)6),
13-
END_COMPOSITE((short)4),
14-
ENCODING((short)17),
15-
VALID_VALUE((short)10),
16-
END_GROUP((short)8),
17-
BEGIN_COMPOSITE((short)3),
18-
END_VAR_DATA((short)16),
1914
BEGIN_GROUP((short)7),
15+
END_GROUP((short)8),
2016
BEGIN_ENUM((short)9),
21-
CHOICE((short)13),
17+
VALID_VALUE((short)10),
2218
END_ENUM((short)11),
2319
BEGIN_SET((short)12),
24-
BEGIN_MESSAGE((short)1),
20+
CHOICE((short)13),
21+
END_SET((short)14),
22+
BEGIN_VAR_DATA((short)15),
23+
END_VAR_DATA((short)16),
24+
ENCODING((short)17),
2525
NULL_VAL((short)255);
2626

2727
private final short value;
@@ -40,23 +40,23 @@ public static SignalCodec get(final short value)
4040
{
4141
switch (value)
4242
{
43-
case 14: return END_SET;
44-
case 15: return BEGIN_VAR_DATA;
43+
case 1: return BEGIN_MESSAGE;
4544
case 2: return END_MESSAGE;
45+
case 3: return BEGIN_COMPOSITE;
46+
case 4: return END_COMPOSITE;
4647
case 5: return BEGIN_FIELD;
4748
case 6: return END_FIELD;
48-
case 4: return END_COMPOSITE;
49-
case 17: return ENCODING;
50-
case 10: return VALID_VALUE;
51-
case 8: return END_GROUP;
52-
case 3: return BEGIN_COMPOSITE;
53-
case 16: return END_VAR_DATA;
5449
case 7: return BEGIN_GROUP;
50+
case 8: return END_GROUP;
5551
case 9: return BEGIN_ENUM;
56-
case 13: return CHOICE;
52+
case 10: return VALID_VALUE;
5753
case 11: return END_ENUM;
5854
case 12: return BEGIN_SET;
59-
case 1: return BEGIN_MESSAGE;
55+
case 13: return CHOICE;
56+
case 14: return END_SET;
57+
case 15: return BEGIN_VAR_DATA;
58+
case 16: return END_VAR_DATA;
59+
case 17: return ENCODING;
6060
case 255: return NULL_VAL;
6161
}
6262

main/java/uk/co/real_logic/sbe/xml/EnumType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import javax.xml.xpath.XPathExpressionException;
2727
import javax.xml.xpath.XPathFactory;
2828
import java.util.Collection;
29-
import java.util.HashMap;
29+
import java.util.LinkedHashMap;
3030
import java.util.Map;
3131

3232
import static uk.co.real_logic.sbe.xml.XmlSchemaParser.handleError;
@@ -42,8 +42,8 @@ public class EnumType extends Type
4242
{
4343
private final PrimitiveType encodingType;
4444
private final PrimitiveValue nullValue;
45-
private final Map<PrimitiveValue, ValidValue> validValueByPrimitiveValueMap = new HashMap<>();
46-
private final Map<String, ValidValue> validValueByNameMap = new HashMap<>();
45+
private final Map<PrimitiveValue, ValidValue> validValueByPrimitiveValueMap = new LinkedHashMap<>();
46+
private final Map<String, ValidValue> validValueByNameMap = new LinkedHashMap<>();
4747

4848
/**
4949
* Construct a new enumType from XML Schema.

0 commit comments

Comments
 (0)