Permalink
Browse files

per: don't build an async state machine when you're not going to go a…

…sync. and update the other impl to match
  • Loading branch information...
benjamin-hodgson committed Feb 26, 2018
1 parent 628fb7f commit 1d6b5f45919363c978de05a5a849835cec6a773b
Showing with 23 additions and 1 deletion.
  1. +12 −1 Eighty/AsyncHtmlEncodingTextWriter.cs
  2. +11 −0 Eighty/HtmlEncodingTextWriter.cs
@@ -127,7 +127,18 @@ public Task WriteRaw(string s)
return WriteRawImpl(s, 0, s.Length);
}
private async Task WriteRawImpl(string s, int start, int count)
private Task WriteRawImpl(string s, int start, int count)
{
if (count <= _buffer.Length - _bufPos)
{
// the whole string fits in the buffer, no need to flush
s.CopyTo(start, _buffer, _bufPos, count);
_bufPos += count;
return Task.CompletedTask;
}
return WriteInChunks(s, start, count);
}
private async Task WriteInChunks(string s, int start, int count)
{
while (count > 0)
{
@@ -129,6 +129,17 @@ public void WriteRaw(string s)
}
private void WriteRawImpl(string s, int start, int count)
{
if (count <= _buffer.Length - _bufPos)
{
// the whole string fits in the buffer, no need to flush
s.CopyTo(start, _buffer, _bufPos, count);
_bufPos += count;
return;
}
WriteInChunks(s, start, count);
}
private void WriteInChunks(string s, int start, int count)
{
while (count > 0)
{

0 comments on commit 1d6b5f4

Please sign in to comment.