Skip to content

Commit

Permalink
Remove unnecessary delegate/closure from NtProcessInfoHelper on Windo…
Browse files Browse the repository at this point in the history
…ws (#50387)
  • Loading branch information
stephentoub authored Mar 29, 2021
1 parent d261384 commit aece157
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ internal static class NtProcessInfoHelper
private const int DefaultCachedBufferSize = 128 * 1024;
#endif

internal static ProcessInfo[] GetProcessInfos(Predicate<int>? processIdFilter = null)
internal static ProcessInfo[] GetProcessInfos(int? processIdFilter = null)
{
ProcessInfo[] processInfos;

Expand Down Expand Up @@ -342,7 +342,7 @@ private static int GetNewBufferSize(int existingBufferSize, int requiredSize)
return newSize;
}

private static unsafe ProcessInfo[] GetProcessInfos(ReadOnlySpan<byte> data, Predicate<int>? processIdFilter)
private static unsafe ProcessInfo[] GetProcessInfos(ReadOnlySpan<byte> data, int? processIdFilter)
{
// Use a dictionary to avoid duplicate entries if any
// 60 is a reasonable number for processes on a normal machine.
Expand All @@ -356,7 +356,7 @@ private static unsafe ProcessInfo[] GetProcessInfos(ReadOnlySpan<byte> data, Pre

// Process ID shouldn't overflow. OS API GetCurrentProcessID returns DWORD.
int processInfoProcessId = pi.UniqueProcessId.ToInt32();
if (processIdFilter == null || processIdFilter(processInfoProcessId))
if (processIdFilter == null || processIdFilter.GetValueOrDefault() == processInfoProcessId)
{
// get information for a process
ProcessInfo processInfo = new ProcessInfo((int)pi.NumberOfThreads)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static ProcessInfo[] GetProcessInfos(string machineName)
else
{
// local case: do not use performance counter and also attempt to get the matching (by pid) process only
ProcessInfo[] processInfos = NtProcessInfoHelper.GetProcessInfos(pid => pid == processId);
ProcessInfo[] processInfos = NtProcessInfoHelper.GetProcessInfos(processId);
if (processInfos.Length == 1)
{
return processInfos[0];
Expand Down

0 comments on commit aece157

Please sign in to comment.