Skip to content

Commit

Permalink
Use Ascii API in HttpConnection.WriteAsciiString (#100180)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Mar 23, 2024
1 parent d981ed9 commit 309eac5
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,15 @@ private void WriteBytes(ReadOnlySpan<byte> bytes)
private void WriteAsciiString(string s)
{
Debug.Assert(Ascii.IsValid(s));
_writeBuffer.EnsureAvailableSpace(s.Length);
int length = Encoding.ASCII.GetBytes(s, _writeBuffer.AvailableSpan);
Debug.Assert(length == s.Length);
Debug.Assert(Encoding.ASCII.GetString(_writeBuffer.AvailableSpan.Slice(0, length)) == s);
_writeBuffer.Commit(length);
OperationStatus status = Ascii.FromUtf16(s, _writeBuffer.AvailableSpan, out int bytesWritten);
Debug.Assert(status == OperationStatus.Done);
Debug.Assert(bytesWritten == s.Length);
_writeBuffer.Commit(s.Length);
}
private void WriteString(string s, Encoding? encoding)
Expand Down

0 comments on commit 309eac5

Please sign in to comment.