Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize ReadOnlyTernaryTree for System.Private.Xml #60076

Merged
merged 10 commits into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
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
Expand Up @@ -140,7 +140,6 @@
<Compile Include="System\Xml\Core\ConformanceLevel.cs" />
<Compile Include="System\Xml\Core\DtdProcessing.cs" />
<Compile Include="System\Xml\Core\EntityHandling.cs" />
<Compile Include="System\Xml\Core\HtmlTernaryTree.cs" />
<Compile Include="System\Xml\Core\IDtdInfo.cs" />
<Compile Include="System\Xml\Core\IDtdParser.cs" />
<Compile Include="System\Xml\Core\IDtdParserAsync.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
// Instead, modify HtmlRawTextWriterGenerator.ttinclude

#nullable disable
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using MS.Internal.Xml;

namespace System.Xml
{
Expand All @@ -27,9 +22,6 @@ internal class HtmlEncodedRawTextWriter : XmlEncodedRawTextWriter
private string _mediaType;
private bool _doNotEscapeUriAttributes;

protected static TernaryTreeReadOnly _elementPropertySearch;
protected static TernaryTreeReadOnly _attributePropertySearch;

private const int StackIncrement = 10;

public HtmlEncodedRawTextWriter(TextWriter writer, XmlWriterSettings settings) : base(writer, settings)
Expand Down Expand Up @@ -112,7 +104,7 @@ public override void WriteStartElement(string prefix, string localName, string n

if (_trackTextContent && _inTextContent != false) { ChangeTextContentMark(false); }

_currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
_currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);
base._bufChars[_bufPos++] = (char)'<';
base.RawText(localName);
base._attrEndPos = _bufPos;
Expand Down Expand Up @@ -309,7 +301,7 @@ public override void WriteStartAttribute(string prefix, string localName, string

if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
_currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
_currentAttributeProperties = TernaryTreeReadOnly.FindAttributeProperty(localName) &
kronic marked this conversation as resolved.
Show resolved Hide resolved
(AttributeProperties)_currentElementProperties;

if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
Expand Down Expand Up @@ -447,13 +439,6 @@ private void Init(XmlWriterSettings settings)
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);

if (_elementPropertySearch == null)
{
// _elementPropertySearch should be init last for the mutli thread safe situation.
_attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
_elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}

_elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
_currentElementProperties = ElementProperties.DEFAULT;
Expand Down Expand Up @@ -660,7 +645,7 @@ private unsafe void WriteUriAttributeText(char* pSrc, char* pSrcEnd)
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && (XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80)
{
*pDst++ = (char)ch;
pSrc++;
Expand Down Expand Up @@ -839,7 +824,7 @@ public override void WriteStartElement(string prefix, string localName, string n
{
Debug.Assert(prefix.Length == 0);

base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
base._currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);

if (_endBlockPos == base._bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
// Instead, modify HtmlRawTextWriterGenerator.ttinclude

#nullable disable
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using MS.Internal.Xml;

namespace System.Xml
{
Expand All @@ -28,9 +23,6 @@ namespace System.Xml
private string _mediaType;
private bool _doNotEscapeUriAttributes;

protected static TernaryTreeReadOnly _elementPropertySearch;
protected static TernaryTreeReadOnly _attributePropertySearch;

private const int StackIncrement = 10;

<# if (WriterType == RawTextWriterType.Encoded) {
Expand Down Expand Up @@ -115,7 +107,7 @@ namespace System.Xml

#><#= SetTextContentMark(4, false) #>

_currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
_currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);
base.<#= BufferName #>[_bufPos++] = (<#= BufferType #>)'<';
base.RawText(localName);
base._attrEndPos = _bufPos;
Expand Down Expand Up @@ -312,7 +304,7 @@ namespace System.Xml

if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
_currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
_currentAttributeProperties = TernaryTreeReadOnly.FindAttributeProperty(localName) &
(AttributeProperties)_currentElementProperties;

if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
Expand Down Expand Up @@ -450,13 +442,6 @@ namespace System.Xml
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);

if (_elementPropertySearch == null)
{
// _elementPropertySearch should be init last for the mutli thread safe situation.
_attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
_elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}

_elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
_currentElementProperties = ElementProperties.DEFAULT;
Expand Down Expand Up @@ -576,9 +561,9 @@ namespace System.Xml
}

<# if (WriterType == RawTextWriterType.Utf8) {#>
while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch <= 0x7F)
<# } else { #>
while (pDst < pDstEnd && _xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)))
<# } #>
{
*pDst++ = (<#= BufferType #>)ch;
Expand Down Expand Up @@ -667,7 +652,7 @@ namespace System.Xml
pDstEnd = pDstBegin + _bufLen;
}

while (pDst < pDstEnd && (_xmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80))
while (pDst < pDstEnd && XmlCharType.IsAttributeValueChar((char)(ch = *pSrc)) && ch < 0x80)
{
*pDst++ = (<#= BufferType #>)ch;
pSrc++;
Expand Down Expand Up @@ -793,7 +778,7 @@ namespace System.Xml
//
// 4). SE SC same as above EE a). check stored blockPro <A></A>
// b). true: indentLevel no change
internal class <#= ClassNameIndent #> : <#= ClassName #>
internal sealed class <#= ClassNameIndent #> : <#= ClassName #>
{
//
// Fields
Expand Down Expand Up @@ -848,7 +833,7 @@ namespace System.Xml
{
Debug.Assert(prefix.Length == 0);

base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
base._currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);

if (_endBlockPos == base._bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
// Instead, modify HtmlRawTextWriterGenerator.ttinclude

#nullable disable
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using MS.Internal.Xml;

namespace System.Xml
{
Expand All @@ -27,9 +22,6 @@ internal class HtmlUtf8RawTextWriter : XmlUtf8RawTextWriter
private string _mediaType;
private bool _doNotEscapeUriAttributes;

protected static TernaryTreeReadOnly _elementPropertySearch;
protected static TernaryTreeReadOnly _attributePropertySearch;

private const int StackIncrement = 10;

public HtmlUtf8RawTextWriter(Stream stream, XmlWriterSettings settings) : base(stream, settings)
Expand Down Expand Up @@ -103,7 +95,7 @@ public override void WriteStartElement(string prefix, string localName, string n
{
Debug.Assert(prefix.Length == 0);

_currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
_currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);
base._bufBytes[_bufPos++] = (byte)'<';
base.RawText(localName);
base._attrEndPos = _bufPos;
Expand Down Expand Up @@ -294,7 +286,7 @@ public override void WriteStartAttribute(string prefix, string localName, string

if ((_currentElementProperties & (ElementProperties.BOOL_PARENT | ElementProperties.URI_PARENT | ElementProperties.NAME_PARENT)) != 0)
{
_currentAttributeProperties = (AttributeProperties)_attributePropertySearch.FindCaseInsensitiveString(localName) &
_currentAttributeProperties = TernaryTreeReadOnly.FindAttributeProperty(localName) &
(AttributeProperties)_currentElementProperties;

if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
Expand Down Expand Up @@ -424,13 +416,6 @@ private void Init(XmlWriterSettings settings)
Debug.Assert((int)ElementProperties.BOOL_PARENT == (int)AttributeProperties.BOOLEAN);
Debug.Assert((int)ElementProperties.NAME_PARENT == (int)AttributeProperties.NAME);

if (_elementPropertySearch == null)
{
// _elementPropertySearch should be init last for the mutli thread safe situation.
_attributePropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlAttributes);
_elementPropertySearch = new TernaryTreeReadOnly(HtmlTernaryTree.htmlElements);
}

_elementScope = new ByteStack(StackIncrement);
_uriEscapingBuffer = new byte[5];
_currentElementProperties = ElementProperties.DEFAULT;
Expand Down Expand Up @@ -809,7 +794,7 @@ public override void WriteStartElement(string prefix, string localName, string n
{
Debug.Assert(prefix.Length == 0);

base._currentElementProperties = (ElementProperties)_elementPropertySearch.FindCaseInsensitiveString(localName);
base._currentElementProperties = TernaryTreeReadOnly.FindElementProperty(localName);

if (_endBlockPos == base._bufPos && (base._currentElementProperties & ElementProperties.BLOCK_WS) != 0)
{
Expand Down
Loading