Skip to content

Commit 909771c

Browse files
committed
Some changes to reduce string allocations
1 parent b9d4685 commit 909771c

File tree

2 files changed

+10
-28
lines changed

2 files changed

+10
-28
lines changed

src/Exceptionless/Extensions/DataDictionaryExtensions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Exceptionless.Dependency;
@@ -105,16 +105,16 @@ public static void AddObject(this IData data, ExtendedDataInfo info, Exceptionle
105105
: client.Configuration.DataExclusions.ToArray();
106106

107107
string name = !String.IsNullOrWhiteSpace(info.Name) ? info.Name.Trim() : null;
108+
Type dataType = info.Data.GetType();
108109
if (String.IsNullOrEmpty(name)) {
109-
name = info.Data.GetType().Name;
110+
name = dataType.Name;
110111
int index = 1;
111112
while (data.Data.ContainsKey(name))
112-
name = info.Data.GetType().Name + index++;
113+
name = dataType.Name + index++;
113114
} else if (name.AnyWildcardMatches(exclusions, true)) {
114115
return;
115116
}
116117

117-
Type dataType = info.Data.GetType();
118118
if (dataType == typeof(bool) || dataType == typeof(string) || dataType.IsNumeric()) {
119119
if (data.Data.ContainsKey(name))
120120
data.Data[name] = info.Data;

src/Exceptionless/Extensions/StringExtensions.cs

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public static bool AnyWildcardMatches(this string value, IEnumerable<string> pat
2626
if (patternsToMatch == null || value == null)
2727
return false;
2828

29-
if (ignoreCase)
30-
value = value.ToLower();
31-
3229
return patternsToMatch.Any(pattern => IsPatternMatch(value, pattern, ignoreCase));
3330
}
3431

@@ -49,33 +46,18 @@ public static bool IsPatternMatch(this string value, string pattern, bool ignore
4946
bool endsWithWildcard = pattern.EndsWith("*");
5047
if (endsWithWildcard)
5148
pattern = pattern.Substring(0, pattern.Length - 1);
52-
53-
if (ignoreCase) {
54-
value = value.ToLower();
55-
pattern = pattern.ToLower();
56-
}
57-
49+
50+
var comparison = ignoreCase ? StringComparison.InvariantCultureIgnoreCase : StringComparison.InvariantCulture;
5851
if (startsWithWildcard && endsWithWildcard)
59-
return value.Contains(pattern);
52+
return value.IndexOf(pattern ?? "", comparison) >= 0;
6053

6154
if (startsWithWildcard)
62-
return value.EndsWith(pattern);
55+
return value.EndsWith(pattern, comparison);
6356

6457
if (endsWithWildcard)
65-
return value.StartsWith(pattern);
66-
67-
return String.Equals(value, pattern);
68-
}
69-
70-
public static string[] SplitAndTrim(this string input, params char[] separator) {
71-
if (String.IsNullOrEmpty(input))
72-
return new string[0];
73-
74-
var result = input.Split(separator, StringSplitOptions.RemoveEmptyEntries);
75-
for (int i = 0; i < result.Length; i++)
76-
result[i] = result[i].Trim();
58+
return value.StartsWith(pattern, comparison);
7759

78-
return result;
60+
return String.Equals(value, pattern, comparison);
7961
}
8062

8163
public static bool ToBoolean(this string input, bool @default = false) {

0 commit comments

Comments
 (0)