Skip to content

Commit

Permalink
per: don't build an async state machine when you're not going to go a…
Browse files Browse the repository at this point in the history
…sync. and update the other impl to match
  • Loading branch information
Benjamin Hodgson committed Feb 26, 2018
1 parent 628fb7f commit 1d6b5f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Eighty/AsyncHtmlEncodingTextWriter.cs
Expand Up @@ -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)
{
Expand Down
11 changes: 11 additions & 0 deletions Eighty/HtmlEncodingTextWriter.cs
Expand Up @@ -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)
{
Expand Down

0 comments on commit 1d6b5f4

Please sign in to comment.