|
5 | 5 | using System.Collections.Generic; |
6 | 6 | using QuickFix.DataDictionary; |
7 | 7 | using DD = QuickFix.DataDictionary.DataDictionary; |
| 8 | +using QuickFix.ObjectPooling; |
8 | 9 |
|
9 | 10 | namespace QuickFix; |
10 | 11 |
|
@@ -853,18 +854,19 @@ protected int BodyLength() |
853 | 854 |
|
854 | 855 | private static string FieldMapToXml(DD? dd, FieldMap fields) |
855 | 856 | { |
856 | | - StringBuilder s = new StringBuilder(); |
| 857 | + using PooledStringBuilder pooledSb = new PooledStringBuilder(); |
| 858 | + StringBuilder s = pooledSb.Builder; |
857 | 859 |
|
858 | 860 | // fields |
859 | 861 | foreach (var f in fields) |
860 | 862 | { |
861 | 863 | s.Append("<field "); |
862 | 864 | if (dd is not null && dd.FieldsByTag.TryGetValue(f.Key, out var value)) |
863 | 865 | { |
864 | | - s.Append("name=\"" + value.Name + "\" "); |
| 866 | + s.Append("name=\"").Append(value.Name).Append("\" "); |
865 | 867 | } |
866 | | - s.Append("number=\"" + f.Key + "\">"); |
867 | | - s.Append("<![CDATA[" + f.Value + "]]>"); |
| 868 | + s.Append("number=\"").Append(f.Key).Append("\">"); |
| 869 | + s.Append("<![CDATA[").Append(f.Value).Append("]]>"); |
868 | 870 | s.Append("</field>"); |
869 | 871 | } |
870 | 872 | // now groups |
@@ -968,7 +970,8 @@ private static StringBuilder FieldMapToJson(StringBuilder sb, DD? dd, FieldMap f |
968 | 970 | /// <returns>an XML string</returns> |
969 | 971 | public string ToXML(DD? dataDictionary = null) |
970 | 972 | { |
971 | | - StringBuilder s = new StringBuilder(); |
| 973 | + using PooledStringBuilder pooledSb = new PooledStringBuilder(); |
| 974 | + StringBuilder s = pooledSb.Builder; |
972 | 975 | s.Append("<message>"); |
973 | 976 | s.Append("<header>"); |
974 | 977 | s.Append(FieldMapToXml(dataDictionary, Header)); |
@@ -1004,7 +1007,8 @@ public string ToJSON(DD? dataDictionary = null, bool convertEnumsToDescriptions |
1004 | 1007 | $"Must be non-null if '{nameof(convertEnumsToDescriptions)}' is true."); |
1005 | 1008 | } |
1006 | 1009 |
|
1007 | | - StringBuilder sb = new StringBuilder().Append('{').Append("\"Header\":{"); |
| 1010 | + using PooledStringBuilder pooledSb = new PooledStringBuilder(); |
| 1011 | + StringBuilder sb = pooledSb.Builder.Append('{').Append("\"Header\":{"); |
1008 | 1012 | FieldMapToJson(sb, dataDictionary, Header, convertEnumsToDescriptions, tagsToMask, maskText).Append("},\"Body\":{"); |
1009 | 1013 | FieldMapToJson(sb, dataDictionary, this, convertEnumsToDescriptions, tagsToMask, maskText).Append("},\"Trailer\":{"); |
1010 | 1014 | FieldMapToJson(sb, dataDictionary, Trailer, convertEnumsToDescriptions, tagsToMask, maskText).Append("}}"); |
|
0 commit comments