Skip to content

Commit 1d6b5f4

Browse files
author
Benjamin Hodgson
committed
per: don't build an async state machine when you're not going to go async. and update the other impl to match
1 parent 628fb7f commit 1d6b5f4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Eighty/AsyncHtmlEncodingTextWriter.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,18 @@ public Task WriteRaw(string s)
127127
return WriteRawImpl(s, 0, s.Length);
128128
}
129129

130-
private async Task WriteRawImpl(string s, int start, int count)
130+
private Task WriteRawImpl(string s, int start, int count)
131+
{
132+
if (count <= _buffer.Length - _bufPos)
133+
{
134+
// the whole string fits in the buffer, no need to flush
135+
s.CopyTo(start, _buffer, _bufPos, count);
136+
_bufPos += count;
137+
return Task.CompletedTask;
138+
}
139+
return WriteInChunks(s, start, count);
140+
}
141+
private async Task WriteInChunks(string s, int start, int count)
131142
{
132143
while (count > 0)
133144
{

Eighty/HtmlEncodingTextWriter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ public void WriteRaw(string s)
129129
}
130130

131131
private void WriteRawImpl(string s, int start, int count)
132+
{
133+
if (count <= _buffer.Length - _bufPos)
134+
{
135+
// the whole string fits in the buffer, no need to flush
136+
s.CopyTo(start, _buffer, _bufPos, count);
137+
_bufPos += count;
138+
return;
139+
}
140+
WriteInChunks(s, start, count);
141+
}
142+
private void WriteInChunks(string s, int start, int count)
132143
{
133144
while (count > 0)
134145
{

0 commit comments

Comments
 (0)