Remove unnecessary Array -> List -> Array conversion in ProcessBaseCommand.AllProcesses (#15052)

This commit is contained in:
xtqqczze 2021-04-12 17:24:41 +01:00 committed by GitHub
parent 49288e4289
commit be9b14a296
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -266,30 +266,17 @@ namespace Microsoft.PowerShell.Commands
}
/// <summary>
/// Retrieve the master list of all processes.
/// Gets an array of all processes.
/// </summary>
/// <value></value>
/// <value>An array of <see cref="Process"/> components that represents all the process resources.</value>
/// <exception cref="System.Security.SecurityException">
/// MSDN does not document the list of exceptions,
/// but it is reasonable to expect that SecurityException is
/// among them. Errors here will terminate the cmdlet.
/// </exception>
internal Process[] AllProcesses
{
get
{
if (_allProcesses == null)
{
List<Process> processes = new();
processes.AddRange(Process.GetProcesses());
_allProcesses = processes.ToArray();
}
internal Process[] AllProcesses => _allProcesses ??= Process.GetProcesses();
return _allProcesses;
}
}
private Process[] _allProcesses = null;
private Process[] _allProcesses;
/// <summary>
/// Add <paramref name="process"/> to <see cref="_matchingProcesses"/>,