Skip to content

Commit be9b14a

Browse files
authored
Remove unnecessary Array -> List -> Array conversion in ProcessBaseCommand.AllProcesses (PowerShell#15052)
1 parent 49288e4 commit be9b14a

File tree

1 file changed

+4
-17
lines changed
  • src/Microsoft.PowerShell.Commands.Management/commands/management

1 file changed

+4
-17
lines changed

src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,30 +266,17 @@ private void RetrieveProcessesByInput()
266266
}
267267

268268
/// <summary>
269-
/// Retrieve the master list of all processes.
269+
/// Gets an array of all processes.
270270
/// </summary>
271-
/// <value></value>
271+
/// <value>An array of <see cref="Process"/> components that represents all the process resources.</value>
272272
/// <exception cref="System.Security.SecurityException">
273273
/// MSDN does not document the list of exceptions,
274274
/// but it is reasonable to expect that SecurityException is
275275
/// among them. Errors here will terminate the cmdlet.
276276
/// </exception>
277-
internal Process[] AllProcesses
278-
{
279-
get
280-
{
281-
if (_allProcesses == null)
282-
{
283-
List<Process> processes = new();
284-
processes.AddRange(Process.GetProcesses());
285-
_allProcesses = processes.ToArray();
286-
}
287-
288-
return _allProcesses;
289-
}
290-
}
277+
internal Process[] AllProcesses => _allProcesses ??= Process.GetProcesses();
291278

292-
private Process[] _allProcesses = null;
279+
private Process[] _allProcesses;
293280

294281
/// <summary>
295282
/// Add <paramref name="process"/> to <see cref="_matchingProcesses"/>,

0 commit comments

Comments
 (0)