Specify the Size of List<T> Instances in InvokeTypeInfo (#50438)
authorBrian Robbins <brianrob@microsoft.com>
Wed, 31 Mar 2021 04:28:50 +0000 (21:28 -0700)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 04:28:50 +0000 (04:28 +0000)
* Initialize List<T> instances in InvokeTypeInfo with known sizes.

* Switch from List<T> to arrays.

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/EventPayload.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/InvokeTypeInfo.cs

index cd34723..98cd97f 100644 (file)
@@ -22,9 +22,9 @@ namespace System.Diagnostics.Tracing
     /// </summary>
     internal sealed class EventPayload : IDictionary<string, object?>
     {
-        internal EventPayload(List<string> payloadNames, List<object?> payloadValues)
+        internal EventPayload(string[] payloadNames, object?[] payloadValues)
         {
-            Debug.Assert(payloadNames.Count == payloadValues.Count);
+            Debug.Assert(payloadNames.Length == payloadValues.Length);
 
             m_names = payloadNames;
             m_values = payloadValues;
@@ -88,7 +88,7 @@ namespace System.Diagnostics.Tracing
             return false;
         }
 
-        public int Count => m_names.Count;
+        public int Count => m_names.Length;
 
         public bool IsReadOnly => true;
 
@@ -142,8 +142,8 @@ namespace System.Diagnostics.Tracing
         }
 
 #region private
-        private readonly List<string> m_names;
-        private readonly List<object?> m_values;
+        private readonly string[] m_names;
+        private readonly object?[] m_values;
 #endregion
     }
 }
index 0cc42de..1fc44ac 100644 (file)
@@ -77,13 +77,13 @@ namespace System.Diagnostics.Tracing
         {
             if (this.properties != null)
             {
-                var membersNames = new List<string>();
-                var membersValues = new List<object?>();
+                var membersNames = new string[this.properties.Length];
+                var membersValues = new object?[this.properties.Length];
                 for (int i = 0; i < this.properties.Length; i++)
                 {
                     object? propertyValue = properties[i].propertyInfo.GetValue(value);
-                    membersNames.Add(properties[i].name);
-                    membersValues.Add(properties[i].typeInfo.GetData(propertyValue));
+                    membersNames[i] = properties[i].name;
+                    membersValues[i] = properties[i].typeInfo.GetData(propertyValue);
                 }
                 return new EventPayload(membersNames, membersValues);
             }