Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit a941264

Browse files
committed
Merge branch 'master' into beta
2 parents 61da809 + b309fc2 commit a941264

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/Titanium.Web.Proxy/Helpers/HttpWriter.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ internal class HttpWriter : ICustomStreamWriter
1818

1919
private static readonly byte[] newLine = ProxyConstants.NewLineBytes;
2020

21-
private static readonly Encoder encoder = Encoding.ASCII.GetEncoder();
22-
23-
private readonly char[] charBuffer;
21+
private static readonly Encoding encoder = Encoding.ASCII;
2422

2523
internal HttpWriter(Stream stream, IBufferPool bufferPool, int bufferSize)
2624
{
2725
BufferSize = bufferSize;
2826
this.stream = stream;
2927
this.bufferPool = bufferPool;
30-
31-
// ASCII encoder max byte count is char count + 1
32-
charBuffer = new char[BufferSize - 1];
3328
}
3429

3530
internal int BufferSize { get; }
@@ -55,12 +50,10 @@ private async Task writeAsyncInternal(string value, bool addNewLine, Cancellatio
5550
int charCount = value.Length;
5651
if (charCount < BufferSize - newLineChars)
5752
{
58-
value.CopyTo(0, charBuffer, 0, charCount);
59-
6053
var buffer = bufferPool.GetBuffer(BufferSize);
6154
try
6255
{
63-
int idx = encoder.GetBytes(charBuffer, 0, charCount, buffer, 0, true);
56+
int idx = encoder.GetBytes(value, 0, charCount, buffer, 0);
6457
if (newLineChars > 0)
6558
{
6659
Buffer.BlockCopy(newLine, 0, buffer, idx, newLineChars);
@@ -76,11 +69,8 @@ private async Task writeAsyncInternal(string value, bool addNewLine, Cancellatio
7669
}
7770
else
7871
{
79-
var charBuffer = new char[charCount];
80-
value.CopyTo(0, charBuffer, 0, charCount);
81-
8272
var buffer = new byte[charCount + newLineChars + 1];
83-
int idx = encoder.GetBytes(charBuffer, 0, charCount, buffer, 0, true);
73+
int idx = encoder.GetBytes(value, 0, charCount, buffer, 0);
8474
if (newLineChars > 0)
8575
{
8676
Buffer.BlockCopy(newLine, 0, buffer, idx, newLineChars);

0 commit comments

Comments
 (0)