Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance patch of JsonConverterHelper.cs #26448

Merged
merged 2 commits into from
Apr 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Microsoft.Rest.Serialization
/// </summary>
public static class JsonConverterHelper
{
private static readonly Regex splitCompiledRegex = new Regex(@"(?<!\\)\.", RegexOptions.Compiled);

/// <summary>
/// Serializes properties of the value object into JsonWriter.
/// </summary>
Expand Down Expand Up @@ -113,19 +115,24 @@ public static string GetPropertyName(this JsonProperty property, out string[] pa

if (!string.IsNullOrEmpty(propertyName))
{
string[] hierarchy = Regex.Split(propertyName, @"(?<!\\)\.")
.Select(p => p?.Replace("\\.", ".")).ToArray();
string[] hierarchy = splitCompiledRegex.Split(propertyName);
PiDiBi marked this conversation as resolved.
Show resolved Hide resolved
for (int i = 0; i < hierarchy.Length; i++)
{
hierarchy[i] = hierarchy[i]?.Replace("\\.", ".");
}

if (hierarchy.Length > 1)
{
propertyName = hierarchy.Last();
parentPath = hierarchy.Take(hierarchy.Length - 1).ToArray();
propertyName = hierarchy[hierarchy.Length - 1];
Array.Resize(ref hierarchy, hierarchy.Length - 1);
parentPath = hierarchy;
}
}

return propertyName;
return propertyName;
PiDiBi marked this conversation as resolved.
Show resolved Hide resolved
}

public static bool IsJsonExtensionData(this JsonProperty property)
=> property.AttributeProvider.GetAttributes(typeof(JsonExtensionDataAttribute), true).Count != 0;
}
}
}