8000 Replace StringCollection with string[] when length is known · PowerShell/PowerShell@8bcb8ca · GitHub
[go: up one dir, main page]

Skip to content

Commit 8bcb8ca

Browse files
committed
Replace StringCollection with string[] when length is known
1 parent 165119d commit 8bcb8ca

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/System.Management.Automation/FormatAndOutput/common/BaseOutputtingCommand.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Collections.Specialized;
76
using System.Management.Automation;
87
using System.Management.Automation.Internal;
98

@@ -1117,33 +1116,42 @@ private void InternalInitialize(ListViewEntry lve)
11171116

11181117
internal static string[] GetProperties(ListViewEntry lve)
11191118
{
1120-
StringCollection props = new StringCollection();
1121-
foreach (ListViewField lvf in lve.listViewFieldList)
1119+
int count = lve.listViewFieldList.Count;
1120+
1121+
if (count == 0)
11221122
{
1123-
props.Add(lvf.label ?? lvf.propertyName);
1123+
return null;
11241124
}
11251125

1126-
if (props.Count == 0)
1127-
return null;
1128-
string[] retVal = new string[props.Count];
1129-
props.CopyTo(retVal, 0);
1130-
return retVal;
1126+
string[] props = new string[count];
1127+
1128+
for (int i = 0; i < count; ++i)
1129+
{
1130+
ListViewField lvf = lve.listViewFieldList[i];
1131+
props[i] = lvf.label ?? lvf.propertyName;
1132+
}
1133+
1134+
return props;
11311135
}
11321136

11331137
internal static string[] GetValues(ListViewEntry lve)
11341138
{
1135-
StringCollection vals = new StringCollection();
1139+
int count = lve.listViewFieldList.Count;
11361140

1137-
foreach (ListViewField lvf in lve.listViewFieldList)
1141+
if (count == 0)
11381142
{
1139-
vals.Add(lvf.formatPropertyField.propertyValue);
1143+
return null;
11401144
}
11411145

1142-
if (vals.Count == 0)
1143-
return null;
1144-
string[] retVal = new string[vals.Count];
1145-
vals.CopyTo(retVal, 0);
1146-
return retVal;
1146+
string[] vals = new string[count];
1147+
1148+
for (int i = 0; i < count; ++i)
1149+
{
1150+
ListViewField lvf = lve.listViewFieldList[i];
1151+
vals[i] = lvf.formatPropertyField.propertyValue;
1152+
}
1153+
1154+
return vals;
11471155
}
11481156

11491157
/// <summary>

0 commit comments

Comments
 (0)
0