Skip to content

Commit a61a7e7

Browse files
committed
Refactored Write ReadOnlySpan of char override to HttpResponseStreamWriter
1 parent 517be5c commit a61a7e7

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Http/WebUtilities/src/HttpResponseStreamWriter.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,21 @@ public override void Write(ReadOnlySpan<char> values)
134134
throw new ObjectDisposedException(nameof(HttpResponseStreamWriter));
135135
}
136136

137-
bool completed;
138-
do
137+
int written = 0;
138+
while (written < values.Length)
139139
{
140140
if (_charBufferCount == _charBufferSize)
141141
{
142142
FlushInternal(flushEncoder: false);
143143
}
144144

145-
completed = CopyToCharBuffer(ref values);
146-
} while (!completed);
145+
written = CopyToCharBuffer(values);
146+
147+
if (written < values.Length)
148+
{
149+
values = values.Slice(written);
150+
}
151+
};
147152
}
148153

149154
public override void Write(string value)
@@ -442,7 +447,7 @@ private void CopyToCharBuffer(char[] values, ref int index, ref int count)
442447
count -= remaining;
443448
}
444449

445-
private bool CopyToCharBuffer(ref ReadOnlySpan<char> values)
450+
private int CopyToCharBuffer(ReadOnlySpan<char> values)
446451
{
447452
var remaining = Math.Min(_charBufferSize - _charBufferCount, values.Length);
448453

@@ -452,13 +457,7 @@ private bool CopyToCharBuffer(ref ReadOnlySpan<char> values)
452457

453458
_charBufferCount += remaining;
454459

455-
if (remaining < values.Length)
456-
{
457-
values = values.Slice(remaining);
458-
return false;
459-
}
460-
461-
return true;
460+
return remaining;
462461
}
463462

464463
[MethodImpl(MethodImplOptions.NoInlining)]

0 commit comments

Comments
 (0)