Skip to content

Commit 4ede8f3

Browse files
committed
Extracted group order arrays into constants, reducing object allocations
1 parent 27c1edf commit 4ede8f3

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

quickfixj-codegenerator/src/main/resources/org/quickfixj/codegenerator/Message.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public class Message extends quickfix.Message {
115115
public static class <xsl:value-of select="@name"/> extends Group {
116116

117117
static final long serialVersionUID = <xsl:value-of select="$serialVersionUID"/>;
118+
private static final int[] ORDER = {<xsl:apply-templates select="field|component|group" mode="group-field-numbers"/>0};
118119

119120
public <xsl:value-of select="@name"/>() {
120-
super(<xsl:value-of select="/fix/fields/field[@name=$groupFieldName]/@number"/>, <xsl:apply-templates select="field|component|group" mode="group-delimeter"/>,
121-
new int[] {<xsl:apply-templates select="field|component|group" mode="group-field-numbers"/>0});
121+
super(<xsl:value-of select="/fix/fields/field[@name=$groupFieldName]/@number"/>, <xsl:apply-templates select="field|component|group" mode="group-delimeter"/>, ORDER);
122122
}
123123
<xsl:apply-templates select="field|component|group" mode="field-accessors"/>
124124
}

quickfixj-codegenerator/src/main/resources/org/quickfixj/codegenerator/MessageSubclass.xsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ import quickfix.Group;</xsl:if>
172172
public static class <xsl:value-of select="@name"/> extends Group {
173173

174174
static final long serialVersionUID = <xsl:value-of select="$serialVersionUID"/>;
175+
private static final int[] ORDER = {<xsl:apply-templates select="field|component|group" mode="group-field-numbers"/>0};
175176

176177
public <xsl:value-of select="@name"/>() {
177-
super(<xsl:value-of select="/fix/fields/field[@name=$groupFieldName]/@number"/>, <xsl:apply-templates select="field|component|group" mode="group-delimeter"/>,
178-
new int[] {<xsl:apply-templates select="field|component|group" mode="group-field-numbers"/> 0 });
178+
super(<xsl:value-of select="/fix/fields/field[@name=$groupFieldName]/@number"/>, <xsl:apply-templates select="field|component|group" mode="group-delimeter"/>, ORDER);
179179
}
180180
<xsl:apply-templates select="field|component|group" mode="field-accessors"/>
181181
}

quickfixj-core/src/main/java/quickfix/FieldMap.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public abstract class FieldMap implements Serializable {
5656

5757
private final TreeMap<Integer, List<Group>> groups = new TreeMap<Integer, List<Group>>();
5858

59+
/**
60+
* Constructs a FieldMap with the given field order.
61+
* The given array must not be modified.
62+
*
63+
* @param fieldOrder the field order, or null if there is none
64+
*/
5965
protected FieldMap(int[] fieldOrder) {
6066
this.fieldOrder = fieldOrder;
6167
fields = new TreeMap<Integer, Field<?>>(
@@ -66,6 +72,12 @@ protected FieldMap() {
6672
this(null);
6773
}
6874

75+
/**
76+
* Returns the order of fields in the group.
77+
* The returned array must not be modified.
78+
*
79+
* @return the field order
80+
*/
6981
public int[] getFieldOrder() {
7082
return fieldOrder;
7183
}

0 commit comments

Comments
 (0)