未验证 提交 da23d5a6 编写于 作者: B Brian Robbins 提交者: GitHub

Specify the Size of List<T> Instances in InvokeTypeInfo (#50438)

* Initialize List<T> instances in InvokeTypeInfo with known sizes.

* Switch from List<T> to arrays.
上级 99d6215e
......@@ -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 @@ public bool ContainsKey(string key)
return false;
}
public int Count => m_names.Count;
public int Count => m_names.Length;
public bool IsReadOnly => true;
......@@ -142,8 +142,8 @@ public bool TryGetValue(string key, [MaybeNullWhen(false)] out object? value)
}
#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
}
}
......@@ -77,13 +77,13 @@ public override void WriteData(PropertyValue value)
{
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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册