Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Text;
using System.Diagnostics;
Expand Down Expand Up @@ -250,9 +249,9 @@ internal void WriteSurrogateCharEntity(char lowChar, char highChar)
_textWriter.Write(';');
}

internal void Write(string text)
internal void Write(ReadOnlySpan<char> text)
{
if (text == null)
if (text.IsEmpty)
{
return;
}
Expand Down Expand Up @@ -301,13 +300,13 @@ internal void Write(string text)
break;
}

char[] helperBuffer = new char[256];
while (true)
{
if (startPos < i)
{
WriteStringFragment(text, startPos, i - startPos, helperBuffer);
_textWriter.Write(text.Slice(startPos, i - startPos));
}

if (i == len)
{
break;
Expand Down Expand Up @@ -516,27 +515,6 @@ internal void WriteEntityRef(string name)
//
// Private implementation methods
//
// This is a helper method to workaround the fact that TextWriter does not have a Write method
// for fragment of a string such as Write( string, offset, count).
// The string fragment will be written out by copying into a small helper buffer and then
// calling textWriter to write out the buffer.
private void WriteStringFragment(string str, int offset, int count, char[] helperBuffer)
{
int bufferSize = helperBuffer.Length;
while (count > 0)
{
int copyCount = count;
if (copyCount > bufferSize)
{
copyCount = bufferSize;
}

str.CopyTo(offset, helperBuffer, 0, copyCount);
_textWriter.Write(helperBuffer, 0, copyCount);
offset += copyCount;
count -= copyCount;
}
}

private void WriteCharEntityImpl(char ch)
{
Expand Down