private static async Task WriteAsyncInternal(StreamWriter _this, char value,
char[] charBuffer, int charPos, int charLen, char[] coreNewLine,
bool autoFlush, bool appendNewLine)
{
if (charPos == charLen)
{
await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this._charPos == 0);
charPos = 0;
}
charBuffer[charPos] = value;
charPos++;
if (appendNewLine)
{
for (int i = 0; i < coreNewLine.Length; i++) // Expect 2 iterations, no point calling BlockCopy
{
if (charPos == charLen)
{
await _this.FlushAsyncInternal(false, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this._charPos == 0);
charPos = 0;
}
charBuffer[charPos] = coreNewLine[i];
charPos++;
}
}
if (autoFlush)
{
await _this.FlushAsyncInternal(true, false, charBuffer, charPos).ConfigureAwait(false);
Debug.Assert(_this._charPos == 0);
charPos = 0;
}
_this.CharPos_Prop = charPos;
}