Skip to content

Commit 789d513

Browse files
authored
Merge pull request connamara#964 from VAllens/Dictionary-access-optimization
Reduce unnecessary ContainsKey function calls to avoid multiple duplicate key lookups
2 parents 4b9593c + 5bc2b8a commit 789d513

File tree

9 files changed

+2430
-2460
lines changed

9 files changed

+2430
-2460
lines changed
Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,91 @@
11
using System;
2+
using System.Collections.Frozen;
23
using System.Collections.Generic;
34

4-
namespace QuickFix.DataDictionary
5+
namespace QuickFix.DataDictionary;
6+
7+
public class DDField
58
{
6-
public class DDField
9+
/// <summary>
10+
/// Represents field data from a DataDictionary file.
11+
/// </summary>
12+
/// <param name="tag"></param>
13+
/// <param name="name"></param>
14+
/// <param name="enums">dictionary of enum=>description values</param>
15+
/// <param name="fixFldType"></param>
16+
public DDField(int tag, String name, IReadOnlyDictionary<String, String> enums, String fixFldType)
717
{
8-
/// <summary>
9-
/// Represents field data from a DataDictionary file.
10-
/// </summary>
11-
/// <param name="tag"></param>
12-
/// <param name="name"></param>
13-
/// <param name="enums">dictionary of enum=>description values</param>
14-
/// <param name="fixFldType"></param>
15-
public DDField(int tag, String name, Dictionary<String, String> enums, String fixFldType)
16-
{
17-
this.Tag = tag;
18-
this.Name = name;
19-
this.EnumDict = enums;
20-
this.FixFldType = fixFldType;
21-
this.FieldType = FieldTypeFromFix(this.FixFldType, out bool isMVFWE);
22-
this.IsMultipleValueFieldWithEnums = isMVFWE;
23-
}
18+
this.Tag = tag;
19+
this.Name = name;
20+
this.EnumDict = enums.ToFrozenDictionary();
21+
this.FixFldType = fixFldType;
22+
this.FieldType = FieldTypeFromFix(this.FixFldType, out bool isMVFWE);
23+
this.IsMultipleValueFieldWithEnums = isMVFWE;
24+
}
2425

25-
public int Tag { get; private set; }
26-
public String Name { get; private set; }
27-
public Dictionary<String, String> EnumDict { get; private set; }
28-
public String FixFldType { get; private set; }
29-
public Type FieldType { get; private set; }
26+
public int Tag { get; private set; }
27+
public String Name { get; private set; }
3028

31-
/// <summary>
32-
/// true if FIX field has an enum and if its type is one of: {MultipleValueString,MultipleStringValue,MultipleCharValue}
33-
/// </summary>
34-
public bool IsMultipleValueFieldWithEnums { get; private set; }
29+
public IReadOnlyDictionary<String, String> EnumDict { get; }
3530

36-
public Boolean HasEnums()
37-
{
38-
return EnumDict.Count > 0;
39-
}
31+
public String FixFldType { get; private set; }
32+
public Type FieldType { get; private set; }
4033

41-
private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums)
42-
{
43-
multipleValueFieldWithEnums = false;
34+
/// <summary>
35+
/// true if FIX field has an enum and if its type is one of: {MultipleValueString,MultipleStringValue,MultipleCharValue}
36+
/// </summary>
37+
public bool IsMultipleValueFieldWithEnums { get; private set; }
4438

45-
switch (type)
46-
{
47-
case "STRING": return typeof(Fields.StringField);
48-
case "CHAR": return typeof(Fields.CharField);
49-
case "PRICE": return typeof(Fields.DecimalField);
50-
case "INT": return typeof(Fields.IntField);
51-
case "AMT": return typeof(Fields.DecimalField);
52-
case "QTY": return typeof(Fields.DecimalField);
53-
case "CURRENCY": return typeof(Fields.StringField);
54-
case "MULTIPLEVALUESTRING": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
55-
case "MULTIPLESTRINGVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
56-
case "MULTIPLECHARVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
57-
case "EXCHANGE": return typeof(Fields.StringField);
58-
case "UTCTIMESTAMP": return typeof(Fields.DateTimeField);
59-
case "BOOLEAN": return typeof(Fields.BooleanField);
60-
case "LOCALMKTDATE": return typeof(Fields.StringField);
61-
case "LOCALMKTTIME": return typeof(Fields.StringField);
62-
case "DATA": return typeof(Fields.StringField);
63-
case "FLOAT": return typeof(Fields.DecimalField);
64-
case "PRICEOFFSET": return typeof(Fields.DecimalField);
65-
case "MONTHYEAR": return typeof(Fields.StringField);
66-
case "DAYOFMONTH": return typeof(Fields.StringField);
67-
case "UTCDATE": return typeof(Fields.DateOnlyField);
68-
case "UTCDATEONLY": return typeof(Fields.DateOnlyField);
69-
case "UTCTIMEONLY": return typeof(Fields.TimeOnlyField);
70-
case "NUMINGROUP": return typeof(Fields.IntField);
71-
case "PERCENTAGE": return typeof(Fields.DecimalField);
72-
case "SEQNUM": return typeof(Fields.ULongField);
73-
case "TAGNUM": return typeof(Fields.IntField);
74-
case "LENGTH": return typeof(Fields.IntField);
75-
case "COUNTRY": return typeof(Fields.StringField);
76-
case "TZTIMEONLY": return typeof(Fields.StringField);
77-
case "TZTIMESTAMP": return typeof(Fields.StringField);
78-
case "XMLDATA": return typeof(Fields.StringField);
79-
case "LANGUAGE": return typeof(Fields.StringField);
80-
case "XID": return typeof(Fields.StringField);
81-
case "XIDREF": return typeof(Fields.StringField);
39+
public Boolean HasEnums()
40+
{
41+
return EnumDict.Count > 0;
42+
}
43+
44+
private Type FieldTypeFromFix(String type, out bool multipleValueFieldWithEnums)
45+
{
46+
multipleValueFieldWithEnums = false;
47+
48+
switch (type)
49+
{
50+
case "STRING": return typeof(Fields.StringField);
51+
case "CHAR": return typeof(Fields.CharField);
52+
case "PRICE": return typeof(Fields.DecimalField);
53+
case "INT": return typeof(Fields.IntField);
54+
case "AMT": return typeof(Fields.DecimalField);
55+
case "QTY": return typeof(Fields.DecimalField);
56+
case "CURRENCY": return typeof(Fields.StringField);
57+
case "MULTIPLEVALUESTRING": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
58+
case "MULTIPLESTRINGVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
59+
case "MULTIPLECHARVALUE": multipleValueFieldWithEnums = true; return typeof(Fields.StringField);
60+
case "EXCHANGE": return typeof(Fields.StringField);
61+
case "UTCTIMESTAMP": return typeof(Fields.DateTimeField);
62+
case "BOOLEAN": return typeof(Fields.BooleanField);
63+
case "LOCALMKTDATE": return typeof(Fields.StringField);
64+
case "LOCALMKTTIME": return typeof(Fields.StringField);
65+
case "DATA": return typeof(Fields.StringField);
66+
case "FLOAT": return typeof(Fields.DecimalField);
67+
case "PRICEOFFSET": return typeof(Fields.DecimalField);
68+
case "MONTHYEAR": return typeof(Fields.StringField);
69+
case "DAYOFMONTH": return typeof(Fields.StringField);
70+
case "UTCDATE": return typeof(Fields.DateOnlyField);
71+
case "UTCDATEONLY": return typeof(Fields.DateOnlyField);
72+
case "UTCTIMEONLY": return typeof(Fields.TimeOnlyField);
73+
case "NUMINGROUP": return typeof(Fields.IntField);
74+
case "PERCENTAGE": return typeof(Fields.DecimalField);
75+
case "SEQNUM": return typeof(Fields.ULongField);
76+
case "TAGNUM": return typeof(Fields.IntField);
77+
case "LENGTH": return typeof(Fields.IntField);
78+
case "COUNTRY": return typeof(Fields.StringField);
79+
case "TZTIMEONLY": return typeof(Fields.StringField);
80+
case "TZTIMESTAMP": return typeof(Fields.StringField);
81+
case "XMLDATA": return typeof(Fields.StringField);
82+
case "LANGUAGE": return typeof(Fields.StringField);
83+
case "XID": return typeof(Fields.StringField);
84+
case "XIDREF": return typeof(Fields.StringField);
8285

83-
case "TIME": return typeof(Fields.DateTimeField);
84-
case "DATE": return typeof(Fields.StringField);
85-
default: throw new DictionaryParseException("invalid type: " + type);
86-
}
86+
case "TIME": return typeof(Fields.DateTimeField);
87+
case "DATE": return typeof(Fields.StringField);
88+
default: throw new DictionaryParseException("invalid type: " + type);
8789
}
8890
}
8991
}

0 commit comments

Comments
 (0)