Skip to content

Commit e8efdf9

Browse files
benaadamsniemyjski
andauthored
Skip pattern maching for empty sets (#258)
* Skip pattern maching for empty sets * Skip pattern maching for empty sets * Fix logic Co-authored-by: Blake Niemyjski <[email protected]>
1 parent 6bbe515 commit e8efdf9

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/Exceptionless/Extensions/DataDictionaryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public static void AddObject(this IData data, ExtendedDataInfo info, Exceptionle
111111
int index = 1;
112112
while (data.Data.ContainsKey(name))
113113
name = dataType.Name + index++;
114-
} else if (name.AnyWildcardMatches(exclusions, true)) {
114+
} else if (exclusions.Length > 0 && name.AnyWildcardMatches(exclusions, true)) {
115115
return;
116116
}
117117

src/Exceptionless/Serializer/DefaultJsonSerializer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ public virtual string Serialize(object model, string[] exclusions = null, int ma
4747
if (maxDepth < 1)
4848
maxDepth = Int32.MaxValue;
4949

50-
var excludedPropertyNames = new HashSet<string>(exclusions ?? new string[0], StringComparer.OrdinalIgnoreCase);
5150
using (var sw = new StringWriter()) {
52-
using (var jw = new JsonTextWriterWithExclusions(sw, excludedPropertyNames)) {
51+
using (var jw = new JsonTextWriterWithExclusions(sw, exclusions)) {
5352
jw.Formatting = Formatting.None;
54-
Func<JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, excludedPropertyNames);
53+
Func<JsonProperty, object, bool> include = (property, value) => ShouldSerialize(jw, property, value, maxDepth, exclusions);
5554
var resolver = new ExceptionlessContractResolver(include);
5655
serializer.ContractResolver = resolver;
5756
if (continueOnSerializationError)
@@ -71,9 +70,9 @@ public virtual object Deserialize(string json, Type type) {
7170
return JsonConvert.DeserializeObject(json, type, _serializerSettings);
7271
}
7372

74-
private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, ISet<string> excludedPropertyNames) {
73+
private bool ShouldSerialize(JsonTextWriterWithDepth jw, JsonProperty property, object obj, int maxDepth, string[] excludedPropertyNames) {
7574
try {
76-
if (excludedPropertyNames != null && (property.UnderlyingName.AnyWildcardMatches(excludedPropertyNames, true) || property.PropertyName.AnyWildcardMatches(excludedPropertyNames, true)))
75+
if (excludedPropertyNames != null && excludedPropertyNames.Length > 0 && (property.UnderlyingName.AnyWildcardMatches(excludedPropertyNames, ignoreCase: true) || property.PropertyName.AnyWildcardMatches(excludedPropertyNames, ignoreCase: true)))
7776
return false;
7877

7978
bool isPrimitiveType = DefaultContractResolver.IsJsonPrimitiveType(property.PropertyType);

src/Exceptionless/Serializer/JsonTextWriterWithExclusions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55

66
namespace Exceptionless.Serializer
77
{
8-
internal class JsonTextWriterWithExclusions : JsonTextWriterWithDepth {
9-
private readonly ISet<string> _excludedPropertyNames;
8+
internal sealed class JsonTextWriterWithExclusions : JsonTextWriterWithDepth {
9+
private readonly string[] _excludedPropertyNames;
1010

11-
public JsonTextWriterWithExclusions(TextWriter textWriter, ISet<string> excludedPropertyNames) : base(textWriter) {
11+
public JsonTextWriterWithExclusions(TextWriter textWriter, string[] excludedPropertyNames) : base(textWriter) {
1212
_excludedPropertyNames = excludedPropertyNames;
1313
}
1414

1515
public override bool ShouldWriteProperty(string name) {
16-
return !name.AnyWildcardMatches(_excludedPropertyNames, true);
16+
var exclusions = _excludedPropertyNames;
17+
return exclusions is null ||
18+
exclusions.Length == 0 ||
19+
!name.AnyWildcardMatches(exclusions, ignoreCase: true);
1720
}
1821
}
1922
}

0 commit comments

Comments
 (0)