Skip to content

Commit 324c3bd

Browse files
Copilotbrianrob
andcommitted
Fix stackalloc issue: use byte-by-byte reading to avoid allocation completely
Co-authored-by: brianrob <[email protected]>
1 parent d95b319 commit 324c3bd

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/TraceEvent/Symbols/SymbolReader.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,17 +1120,11 @@ private bool IsMsfzFile(string filePath)
11201120
return false;
11211121
}
11221122

1123-
Span<byte> buffer = stackalloc byte[headerBytes.Length];
1124-
int bytesRead = stream.Read(buffer);
1125-
1126-
if (bytesRead != headerBytes.Length)
1127-
{
1128-
return false;
1129-
}
1130-
1123+
// Read and compare byte by byte to avoid allocation
11311124
for (int i = 0; i < headerBytes.Length; i++)
11321125
{
1133-
if (buffer[i] != headerBytes[i])
1126+
int b = stream.ReadByte();
1127+
if (b == -1 || b != headerBytes[i])
11341128
{
11351129
return false;
11361130
}

0 commit comments

Comments
 (0)