Avoid unnecessary StringCollection allocation in formatting code (#15832)
This commit is contained in:
parent
5e15f66f97
commit
3733a0bb37
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Management.Automation;
|
using System.Management.Automation;
|
||||||
using System.Management.Automation.Internal;
|
using System.Management.Automation.Internal;
|
||||||
|
|
||||||
|
@ -1117,33 +1116,40 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||||
|
|
||||||
internal static string[] GetProperties(ListViewEntry lve)
|
internal static string[] GetProperties(ListViewEntry lve)
|
||||||
{
|
{
|
||||||
StringCollection props = new StringCollection();
|
int count = lve.listViewFieldList.Count;
|
||||||
foreach (ListViewField lvf in lve.listViewFieldList)
|
|
||||||
|
if (count == 0)
|
||||||
{
|
{
|
||||||
props.Add(lvf.label ?? lvf.propertyName);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.Count == 0)
|
string[] result = new string[count];
|
||||||
return null;
|
for (int index = 0; index < result.Length; ++index)
|
||||||
string[] retVal = new string[props.Count];
|
{
|
||||||
props.CopyTo(retVal, 0);
|
ListViewField lvf = lve.listViewFieldList[index];
|
||||||
return retVal;
|
result[index] = lvf.label ?? lvf.propertyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string[] GetValues(ListViewEntry lve)
|
internal static string[] GetValues(ListViewEntry lve)
|
||||||
{
|
{
|
||||||
StringCollection vals = new StringCollection();
|
int count = lve.listViewFieldList.Count;
|
||||||
|
|
||||||
foreach (ListViewField lvf in lve.listViewFieldList)
|
if (count == 0)
|
||||||
{
|
{
|
||||||
vals.Add(lvf.formatPropertyField.propertyValue);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vals.Count == 0)
|
string[] result = new string[count];
|
||||||
return null;
|
for (int index = 0; index < result.Length; ++index)
|
||||||
string[] retVal = new string[vals.Count];
|
{
|
||||||
vals.CopyTo(retVal, 0);
|
ListViewField lvf = lve.listViewFieldList[index];
|
||||||
return retVal;
|
result[index] = lvf.formatPropertyField.propertyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue