-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
Labels
Description
Description
In advance sorry for my english and sorry if this "is not a bug".
Right now in System.IO.Stream.ReadByte the code allocates an 1-length array for return the only byte read done in Read(byte[], int, int)
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Stream.cs
Lines 697 to 702 in c9d8f80
| public virtual int ReadByte() | |
| { | |
| var oneByteArray = new byte[1]; | |
| int r = Read(oneByteArray, 0, 1); | |
| return r == 0 ? -1 : oneByteArray[0]; | |
| } |
Reproduction Steps
Just that.
Expected behavior
public virtual int ReadByte()
{
var oneByteArray = (stackalloc byte[1]);
int r = Read(oneByteArray);
return r == 0 ? -1 : oneByteArray[0];
}Actual behavior
Actually a call to ReadByte can produce unnecesary GCs (and some child classes and developers that are unaware of this use it a lot).
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Reactions are currently unavailable