Skip to content

Commit

Permalink
Minor cleanup in SnapshotObject and HeapSnapshot.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrp committed Jul 13, 2022
1 parent ab596e1 commit e1eff22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/system/HeapSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public IEnumerable<HeapBlockSnapshot> EnumerateHeapBlocks()
yield break;
}

unsafe HeapBlockSnapshot? CreateHeapBlock()
static unsafe HeapBlockSnapshot CreateHeapBlock(in HEAPENTRY32 entry)
{
// Cannot use unsafe code in iterators...

return new(
(int)entry.th32ProcessID,
(nint)entry.th32HeapID,
Expand All @@ -49,8 +51,7 @@ public IEnumerable<HeapBlockSnapshot> EnumerateHeapBlocks()
(HeapBlockSnapshotFlags)entry.dwFlags);
}

if (CreateHeapBlock() is HeapBlockSnapshot heapBlock)
yield return heapBlock;
yield return CreateHeapBlock(entry);

result = Win32.Heap32Next(ref entry);
}
Expand Down
13 changes: 7 additions & 6 deletions src/system/SnapshotObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public IEnumerable<ProcessSnapshot> EnumerateProcesses()
if (Marshal.GetLastPInvokeError() != (int)WIN32_ERROR.ERROR_NO_MORE_FILES)
throw new Win32Exception();

yield break;
break;
}

if (entry.dwSize == Unsafe.SizeOf<PROCESSENTRY32W>())
Expand All @@ -78,17 +78,18 @@ public IEnumerable<ModuleSnapshot> EnumerateModules()
if (Marshal.GetLastPInvokeError() != (int)WIN32_ERROR.ERROR_NO_MORE_FILES)
throw new Win32Exception();

yield break;
break;
}

static ModuleSnapshot CreateModule(ref MODULEENTRY32W entry)
static ModuleSnapshot CreateModule(in MODULEENTRY32W entry)
{
// Cannot use unsafe code in iterators...

return new((int)entry.th32ProcessID, entry.hModule, entry.modBaseAddr, (int)entry.modBaseSize);
}

if (entry.dwSize == Unsafe.SizeOf<MODULEENTRY32W>())
yield return CreateModule(ref entry);
yield return CreateModule(entry);

result = Win32.Module32NextW(handle, ref entry);
}
Expand All @@ -111,7 +112,7 @@ public IEnumerable<ThreadSnapshot> EnumerateThreads()
if (Marshal.GetLastPInvokeError() != (int)WIN32_ERROR.ERROR_NO_MORE_FILES)
throw new Win32Exception();

yield break;
break;
}

if (entry.dwSize == Unsafe.SizeOf<THREADENTRY32>())
Expand All @@ -138,7 +139,7 @@ public IEnumerable<HeapSnapshot> EnumerateHeaps()
if (Marshal.GetLastPInvokeError() != (int)WIN32_ERROR.ERROR_NO_MORE_FILES)
throw new Win32Exception();

yield break;
break;
}

if (entry.dwSize == (uint)Unsafe.SizeOf<HEAPLIST32>())
Expand Down

0 comments on commit e1eff22

Please sign in to comment.