From aa6cf343ff24d17b961f7917c04c91f98efef5a0 Mon Sep 17 00:00:00 2001 From: David Bures <12524436+PiDiBi@users.noreply.github.com> Date: Tue, 18 Jan 2022 12:30:42 -0800 Subject: [PATCH 1/2] performance update --- .../Serialization/JsonConverterHelper.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs b/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs index e5eaee3cf114..713d2b5e292d 100644 --- a/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs +++ b/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs @@ -19,6 +19,8 @@ namespace Microsoft.Rest.Serialization /// public static class JsonConverterHelper { + private static readonly Regex splitCompiledRegex = new Regex(@"(? /// Serializes properties of the value object into JsonWriter. /// @@ -108,24 +110,29 @@ public static string GetPropertyName(this JsonProperty property, out string[] pa throw new ArgumentNullException("property"); } - string propertyName = property.PropertyName; + string propertyName = name; parentPath = new string[0]; if (!string.IsNullOrEmpty(propertyName)) { - string[] hierarchy = Regex.Split(propertyName, @"(? p?.Replace("\\.", ".")).ToArray(); + string[] hierarchy = splitCompiledRegex.Split(propertyName); + 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; } public static bool IsJsonExtensionData(this JsonProperty property) => property.AttributeProvider.GetAttributes(typeof(JsonExtensionDataAttribute), true).Count != 0; } -} \ No newline at end of file +} From ca4520ff0e8c434a3b41413dd68cd53ec757c306 Mon Sep 17 00:00:00 2001 From: David Bures <12524436+PiDiBi@users.noreply.github.com> Date: Tue, 18 Jan 2022 12:34:49 -0800 Subject: [PATCH 2/2] fix --- .../ClientRuntime/Serialization/JsonConverterHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs b/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs index 713d2b5e292d..b48de950ff1c 100644 --- a/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs +++ b/sdk/mgmtcommon/ClientRuntime/ClientRuntime/Serialization/JsonConverterHelper.cs @@ -110,7 +110,7 @@ public static string GetPropertyName(this JsonProperty property, out string[] pa throw new ArgumentNullException("property"); } - string propertyName = name; + string propertyName = property.PropertyName; parentPath = new string[0]; if (!string.IsNullOrEmpty(propertyName))