Skip to content

Commit fb8d131

Browse files
committed
Use ordinal string comparer
1 parent 1ce11ea commit fb8d131

File tree

8 files changed

+37
-18
lines changed

8 files changed

+37
-18
lines changed

StatePrinter.Tests/PerformanceTests/ManySmallCollections.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public void TestTheOverheadOfStartingUp()
6262
/// <summary>
6363
/// Many small objects reveals the overhead of introspecting types.
6464
///
65+
/// V.3.0.0
6566
//1000: Time: 159 length 123003
6667
//2000: Time: 18 length 246003
6768
//4000: Time: 35 length 492003
@@ -85,9 +86,15 @@ public void DumpManySmallCollections()
8586

8687
/// <summary>
8788
/// Printing 1.000.000 objects.
89+
/// V3.0.0
8890
//curly: 17906 length: 195888912
8991
//json: 11433 length: 123000003
9092
//xml: 17106 length: 232000033
93+
//
94+
// v3.0.1
95+
//curly: 18197 length: 195888912
96+
//json: 11139 length: 123000003
97+
//xml: 14419 length: 232000033
9198
/// </summary>
9299
[Test]
93100
public void TiminAllOutputFormattersAtNElements()

StatePrinter.Tests/PerformanceTests/ManySmallObjects.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,23 @@ public void TestTheOverheadOfStartingUp()
9191
///
9292
///
9393
/// Version 2.2 - HPPavilion 7
94-
/// 1000: 158
95-
/// 2000: 8
96-
/// 4000: 19
97-
/// 8000: 50
9894
/// 16000: 86
9995
/// 32000: 175
10096
/// 64000: 371
10197
/// 128000: 781
10298
/// 256000: 1590
10399
/// 512000: 3217
104100
/// 1024000: 6265
101+
///
102+
///
103+
/// version 3.0.1 - HPPavilion 7
104+
/// 16000: 50
105+
/// 32000: 112
106+
/// 64000: 275
107+
/// 128000: 551
108+
/// 256000: 1078
109+
/// 512000: 2010
110+
/// 1024000: 4507
105111
/// </summary>
106112
[Test]
107113
public void DumpManySmallObjects()
@@ -114,9 +120,15 @@ public void DumpManySmallObjects()
114120

115121
/// <summary>
116122
/// Printing 1.000.000 objects.
123+
/// v2.xx
117124
/// curly: 6959 length: 62888908
118125
/// json: 6578 length: 59000006
119126
/// xml: 8036 length: 89000074
127+
///
128+
/// v3.0.1
129+
/// curly: 6596 length: 82888914
130+
/// json: 3749 length: 58000003
131+
/// xml: 4859 length: 93000035
120132
/// </summary>
121133
[Test]
122134
public void TiminAllOutputFormattersAtNElements()

StatePrinter/FieldHarvesters/HarvestHelper.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public IEnumerable<MemberInfo> GetFieldsAndProperties(Type type, BindingFlags fl
9292
static bool NonBackingFieldFilter(MemberInfo x)
9393
{
9494
return x.MemberType == MemberTypes.Field
95-
&& !x.Name.EndsWith(BackingFieldSuffix);
95+
&& !x.Name.EndsWith(BackingFieldSuffix, StringComparison.Ordinal);
9696
}
9797

9898
static bool IndexerFilter(MemberInfo x)
@@ -109,10 +109,10 @@ static bool IndexerFilter(MemberInfo x)
109109
public bool IsHarvestable(Type type)
110110
{
111111
var typename = type.ToString();
112-
if (typename.StartsWith("System.Reflection")
113-
|| typename.StartsWith("System.Runtime")
114-
|| typename.StartsWith("System.SignatureStruct")
115-
|| typename.StartsWith("System.Func"))
112+
if (typename.StartsWith("System.Reflection", StringComparison.Ordinal)
113+
|| typename.StartsWith("System.Runtime", StringComparison.Ordinal)
114+
|| typename.StartsWith("System.SignatureStruct", StringComparison.Ordinal)
115+
|| typename.StartsWith("System.Func", StringComparison.Ordinal))
116116
return false;
117117
return true;
118118
}
@@ -122,7 +122,7 @@ public bool IsHarvestable(Type type)
122122
/// </summary>
123123
public string SanitizeFieldName(string fieldName)
124124
{
125-
return fieldName.StartsWith("<")
125+
return fieldName.StartsWith("<", StringComparison.Ordinal)
126126
? fieldName.Substring(1).Replace(BackingFieldSuffix, "")
127127
: fieldName;
128128
}

StatePrinter/FieldHarvesters/PublicFieldsHarvester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public List<SanitizedFieldInfo> GetFields(Type type)
5151
fields.Where(
5252
x =>
5353
((FieldInfo)x.FieldInfo).IsPublic
54-
|| x.FieldInfo.Name.EndsWith(HarvestHelper.BackingFieldSuffix));
54+
|| x.FieldInfo.Name.EndsWith(HarvestHelper.BackingFieldSuffix, StringComparison.Ordinal));
5555

5656
return res.ToList();
5757
}

StatePrinter/OutputFormatters/JsonStyle.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ string MakeFieldValue(Token token, string value)
198198
if (token.Field.Key != null)
199199
{
200200
return IsQuoted(token.Field.Key)
201-
? string.Format("{0}: {1}", token.Field.Key, value)
202-
: string.Format("\"{0}\": {1}", token.Field.Key, value);
201+
? string.Concat(token.Field.Key, ": ", value)
202+
: string.Concat("\"", token.Field.Key, "\": ", value);
203203
}
204204

205205
// Field.Name is empty if the ROOT-element-name has not been supplied.
206206
if (string.IsNullOrEmpty(token.Field.Name))
207207
return value;
208208

209-
return string.Format("\"{0}\": {1}", token.Field.Name, value);
209+
return string.Concat("\"", token.Field.Name, "\": ", value);
210210
}
211211

212212
/// <summary>
@@ -234,7 +234,7 @@ string OptionalComma(List<Token> tokens, int position)
234234

235235
bool IsQuoted(string s)
236236
{
237-
return s.Length >= 2 && s.StartsWith("\"") && s.EndsWith("\"");
237+
return s.Length >= 2 && s.StartsWith("\"", StringComparison.Ordinal) && s.EndsWith("\"", StringComparison.Ordinal);
238238
}
239239
}
240240
}

StatePrinter/OutputFormatters/XmlStyle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private string TagName(Token token, out string keyAttr)
141141

142142
private string Unquote(string s)
143143
{
144-
return s.Length >= 2 && s.StartsWith("\"") && s.EndsWith("\"")
144+
return s.Length >= 2 && s.StartsWith("\"", StringComparison.Ordinal) && s.EndsWith("\"", StringComparison.Ordinal)
145145
? s.Substring(1, s.Length - 2) : s;
146146
}
147147
}

StatePrinter/StatePrinter.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<DefineConstants>TRACE</DefineConstants>
3737
<ErrorReport>prompt</ErrorReport>
3838
<WarningLevel>4</WarningLevel>
39-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
39+
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
4040
</PropertyGroup>
4141
<PropertyGroup>
4242
<ApplicationIcon>gfx\stateprinter.ico</ApplicationIcon>

StatePrinter/TestAssistance/EnvironmentReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public bool UseTestAutoRewrite()
3030
string result = Environment.GetEnvironmentVariable(
3131
Usetestautorewrite,
3232
EnvironmentVariableTarget.User);
33-
return "true".Equals(result);
33+
return "true".Equals(result, StringComparison.Ordinal);
3434
}
3535
}
3636
}

0 commit comments

Comments
 (0)