diff --git a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
index 619a6c4fbb7152..322b1cd24f49ff 100644
--- a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
+++ b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj
@@ -140,7 +140,6 @@
-
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlEncodedRawTextWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlEncodedRawTextWriter.cs
index b4210f187a4116..a824c569749824 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlEncodedRawTextWriter.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlEncodedRawTextWriter.cs
@@ -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
{
@@ -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)
@@ -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;
@@ -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) &
(AttributeProperties)_currentElementProperties;
if ((_currentAttributeProperties & AttributeProperties.BOOLEAN) != 0)
@@ -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;
@@ -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++;
@@ -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)
{
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlRawTextWriterGenerator.ttinclude b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlRawTextWriterGenerator.ttinclude
index 3af8316ae748f4..a5b08afd0b976f 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlRawTextWriterGenerator.ttinclude
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlRawTextWriterGenerator.ttinclude
@@ -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
{
@@ -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) {
@@ -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;
@@ -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)
@@ -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;
@@ -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;
@@ -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++;
@@ -793,7 +778,7 @@ namespace System.Xml
//
// 4). SE SC same as above EE a). check stored blockPro
// b). true: indentLevel no change
- internal class <#= ClassNameIndent #> : <#= ClassName #>
+ internal sealed class <#= ClassNameIndent #> : <#= ClassName #>
{
//
// Fields
@@ -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)
{
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlTernaryTree.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlTernaryTree.cs
deleted file mode 100644
index 36450f80e4e651..00000000000000
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlTernaryTree.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-// This file is generated by TernaryTreeGenerator.cs,
-// and is used by the TernaryTreeRO class.
-
-namespace System.Xml
-{
- //
- // It contains the state for a ternary tree used to map HTML
- // keywords to XSL output properties.
- //
- // Do not modify this file directly! (as if you could)
- //
- internal abstract class HtmlTernaryTree
- {
- internal static byte[] htmlElements = {
- 73, 4, 147, 0, 77, 140, 162, 0, 71, 0, 0, 0, 0, 0, 0, 11, 68, 4, 85, 0, 73, 71, 92, 0, 86, 81, 0, 0,
- 0, 0, 0, 64, 66, 3, 45, 0, 82, 21, 55, 0, 0, 0, 0, 8, 65, 0, 0, 0, 82, 4, 0, 0, 69, 0, 0, 0,
- 65, 0, 0, 0, 0, 0, 0, 75, 68, 7, 8, 0, 68, 0, 0, 0, 82, 0, 0, 0, 69, 0, 0, 0, 83, 0, 0, 0,
- 83, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 1, 80, 0, 0, 0, 80, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0,
- 84, 0, 0, 0, 0, 0, 0, 64, 65, 0, 9, 0, 83, 0, 0, 0, 69, 0, 0, 0, 70, 5, 0, 0, 79, 0, 0, 0,
- 78, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 73, 76, 0, 10, 0, 79, 0, 0, 0, 67, 0, 0, 0,
- 75, 0, 0, 0, 81, 0, 0, 0, 85, 0, 0, 0, 79, 0, 0, 0, 84, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 65,
- 79, 0, 0, 0, 68, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 64, 67, 0, 0, 0, 79, 3, 0, 0, 76, 0, 0, 0,
- 0, 0, 22, 72, 65, 0, 13, 0, 80, 0, 0, 0, 84, 0, 0, 0, 73, 0, 0, 0, 79, 0, 0,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, 0, 0, 77, 0, 0, 0, 0, 0, 0, 72,
- 84, 3, 65, 0, 68, 28, 38, 0, 0, 0, 0, 66, 83, 8, 0, 0, 69, 6, 15, 0, 76, 0, 0, 0, 69, 0, 0, 0,
- 67, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 64, 81, 0, 0, 0, 0, 0, 0, 1, 67, 0, 0, 0,
- 82, 0, 0, 0, 73, 0, 0, 0, 80, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 19, 84, 0, 0, 0, 89, 4, 0, 0,
- 76, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 80, 82, 0, 0, 0, 73, 0, 0, 0, 75, 0, 0, 0, 69, 0, 0, 0,
- 0, 0, 0, 64, 65, 0, 5, 0, 66, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 65, 66, 0, 0, 0,
- 79, 0, 0, 0, 68, 0, 0, 0, 89, 0, 0, 0, 0, 0, 0, 64, 72, 5, 19, 0, 69, 17, 0, 0, 65, 0, 0, 0,
- 68, 0, 0, 0, 0, 0, 0, 64, 70, 5, 0, 0, 79, 0, 0, 0, 79, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 64,
- 69, 0, 0, 0, 88, 0, 0, 0, 84, 0, 0, 0, 65, 0, 0, 0, 82, 0, 0, 0, 69, 0, 0, 0, 65, 0, 0, 0,
- 0, 0, 0, 2, 0, 0, 0, 66, 82, 2, 0, 0, 0, 0, 0, 64, 73, 0, 0, 0, 84, 0, 0, 0, 76, 0, 0, 0,
- 69, 0, 0, 0, 0, 0, 0, 64, 85, 0, 3, 0, 76, 0, 0, 0, 0, 0, 0, 66, 88, 0, 0, 0, 77, 0, 0, 0,
- 80, 0, 0, 0, 0, 0, 0, 64,
- };
- internal static byte[] htmlAttributes = {
- 72, 5, 77, 0, 82, 0, 0, 0, 69, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 1, 67, 12, 40, 0, 79, 7, 0, 0,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0, 0, 0,
- 76, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 2, 73, 0, 6, 0, 83, 0, 0, 0, 77, 0, 0, 0, 65, 0, 0, 0,
- 80, 0, 0, 0, 0, 0, 0, 2, 76, 0, 0, 0, 79, 0, 0, 0, 78, 0, 0, 0, 71, 0, 0, 0, 68, 0, 0, 0,
- 69, 0, 0, 0, 83, 0, 0, 0, 67, 0, 0, 0, 0, 0, 0, 1, 72, 0, 9, 0, 82, 0, 0, 0, 69, 0, 0, 0,
- 70, 0, 0, 0, 0, 0, 0, 2, 65, 0, 0, 0, 77, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 1, 82, 0, 0, 0,
- 69, 0, 0, 0, 83, 0, 0, 0, 73, 0, 0, 0, 90, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 2, 82, 14, 22, 0,
- 69, 0, 0, 0, 65, 0, 0, 0, 68, 0, 0, 0, 79, 0, 0, 0, 78, 0, 0, 0, 76, 0, 0, 0, 89, 0, 0, 0,
- 0, 0, 0, 2, 87, 0, 0, 0, 82, 0, 0, 0, 65, 0, 0, 0, 80, 0, 0, 0, 0, 0, 0, 2, 80, 0, 0, 0,
- 82, 0, 0, 0, 79, 0, 0, 0, 70, 0, 0, 0, 73, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0, 0, 0, 0, 1,
- 83, 0, 12, 0, 82, 3, 0, 0, 67, 0, 0, 0, 0, 0, 0, 1, 69, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0,
- 67, 0, 0, 0, 84, 0, 0, 0, 69, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 2, 85, 0, 0, 0, 83, 0, 0, 0,
- 69, 0, 0, 0, 77, 0, 0, 0, 65, 0, 0, 0, 80, 0, 0, 0, 0, 0, 0, 1,
- };
- }
-}
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlUtf8RawTextWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlUtf8RawTextWriter.cs
index 2d3597534cb58d..5bf76a9ad7e84c 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlUtf8RawTextWriter.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/HtmlUtf8RawTextWriter.cs
@@ -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
{
@@ -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)
@@ -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;
@@ -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)
@@ -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;
@@ -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)
{
diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
index f345e151b61cb2..05a5ffc3a5ecfb 100644
--- a/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
+++ b/src/libraries/System.Private.Xml/src/System/Xml/Core/ReadOnlyTernaryTree.cs
@@ -1,21 +1,32 @@
// 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.Diagnostics;
-
namespace System.Xml
{
- // Array index to indicate the meaning of the each byte.
- internal enum TernaryTreeByte { characterByte = 0, leftTree = 1, rightTree = 2, data = 3 };
-
//
// XSL HTML output method properties
//
// Keep the first four bits in sync, so that the element and attribute mask operation can be combined.
- internal enum ElementProperties : uint { DEFAULT = 0, URI_PARENT = 1, BOOL_PARENT = 2, NAME_PARENT = 4, EMPTY = 8, NO_ENTITIES = 16, HEAD = 32, BLOCK_WS = 64, HAS_NS = 128 }
- internal enum AttributeProperties : uint { DEFAULT = 0, URI = 1, BOOLEAN = 2, NAME = 4 }
+ internal enum ElementProperties : uint
+ {
+ DEFAULT = 0,
+ URI_PARENT = 1,
+ BOOL_PARENT = 2,
+ NAME_PARENT = 4,
+ EMPTY = 8,
+ NO_ENTITIES = 16,
+ HEAD = 32,
+ BLOCK_WS = 64,
+ HAS_NS = 128
+ }
+
+ internal enum AttributeProperties : uint
+ {
+ DEFAULT = 0,
+ URI = 1,
+ BOOLEAN = 2,
+ NAME = 4
+ }
/**
@@ -27,16 +38,97 @@ internal enum AttributeProperties : uint { DEFAULT = 0, URI = 1, BOOLEAN = 2, NA
*
* Note: Only strings composed of ASCII characters can exist in the tree.
*/
- internal sealed class TernaryTreeReadOnly
+ internal static class TernaryTreeReadOnly
{
- private readonly byte[] _nodeBuffer;
-
- //define the array positions
-
-
- public TernaryTreeReadOnly(byte[] nodeBuffer)
+ // Array index to indicate the meaning of the each byte.
+ private enum TernaryTreeByte
+ {
+ CharacterByte = 0,
+ LeftTree = 1,
+ RightTree = 2,
+ Data = 3
+ }
+ private static ReadOnlySpan HtmlElements => new byte[]
+ {
+ 73, 4, 147, 0, 77, 140, 162, 0, 71, 0, 0, 0, 0, 0, 0, 11, 68, 4, 85, 0, 73, 71, 92, 0, 86, 81, 0, 0,
+ 0, 0, 0, 64, 66, 3, 45, 0, 82, 21, 55, 0, 0, 0, 0, 8, 65, 0, 0, 0, 82, 4, 0, 0, 69, 0, 0, 0,
+ 65, 0, 0, 0, 0, 0, 0, 75, 68, 7, 8, 0, 68, 0, 0, 0, 82, 0, 0, 0, 69, 0, 0, 0, 83, 0, 0, 0,
+ 83, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 1, 80, 0, 0, 0, 80, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0,
+ 84, 0, 0, 0, 0, 0, 0, 64, 65, 0, 9, 0, 83, 0, 0, 0, 69, 0, 0, 0, 70, 5, 0, 0, 79, 0, 0, 0,
+ 78, 0, 0, 0, 84, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 73, 76, 0, 10, 0, 79, 0, 0, 0, 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
+ 83, 0, 12, 0, 82, 3, 0, 0, 67, 0, 0, 0, 0, 0, 0, 1, 69, 0, 0, 0, 76, 0, 0, 0, 69, 0, 0, 0,
+ 67, 0, 0, 0, 84, 0, 0, 0, 69, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 2, 85, 0, 0, 0, 83, 0, 0, 0,
+ 69, 0, 0, 0, 77, 0, 0, 0, 65, 0, 0, 0, 80, 0, 0, 0, 0, 0, 0, 1,
+ };
+ public static ElementProperties FindElementProperty(ReadOnlySpan stringToFind)
+ {
+ return (ElementProperties)FindCaseInsensitiveString(stringToFind, HtmlElements);
+ }
+ public static AttributeProperties FindAttributeProperty(ReadOnlySpan stringToFind)
{
- _nodeBuffer = nodeBuffer;
+ return (AttributeProperties)FindCaseInsensitiveString(stringToFind, HtmlAttributes);
}
/* ----------------------------------------------------------------------------
@@ -45,53 +137,61 @@ public TernaryTreeReadOnly(byte[] nodeBuffer)
Find a Unicode string in the ternary tree and return the data byte it's
mapped to. Find is case-insensitive.
*/
- public byte FindCaseInsensitiveString(string stringToFind)
+ private static byte FindCaseInsensitiveString(ReadOnlySpan stringToFind, ReadOnlySpan nodeBuffer)
{
- //Debug.Assert(wszFind != null && wszFind.Length != 0);
-
int stringPos = 0, nodePos = 0;
- int charToFind, charInTheTree;
- byte[] node = _nodeBuffer;
+ int charToFind = stringToFind[stringPos];
- charToFind = stringToFind[stringPos];
+ if (charToFind > 'z')
+ {
+ return 0; // Ternary tree only stores ASCII strings
+ }
- if (charToFind > 'z') return 0; // Ternary tree only stores ASCII strings
- if (charToFind >= 'a') charToFind -= ('a' - 'A'); // Normalize to upper case
+ if (charToFind >= 'a')
+ {
+ charToFind -= 'a' - 'A'; // Normalize to upper case
+ }
while (true)
{
int pos = nodePos * 4;
-
- charInTheTree = node[pos + (int)TernaryTreeByte.characterByte];
+ int charInTheTree = nodeBuffer[pos + (int)TernaryTreeByte.CharacterByte];
//Console.WriteLine("charToFind: {0},charInTheTree: {1}, nodePos: {2}", charToFind, charInTheTree, nodePos);
if (charToFind < charInTheTree)
{
// If input character is less than the tree character, take the left branch
- if (node[pos + (int)TernaryTreeByte.leftTree] == 0x0)
+ if (nodeBuffer[pos + (int)TernaryTreeByte.LeftTree] == 0x0)
{
break;
}
- nodePos = nodePos + node[pos + (int)TernaryTreeByte.leftTree];
+
+ nodePos += nodeBuffer[pos + (int)TernaryTreeByte.LeftTree];
}
else if (charToFind > charInTheTree)
{
// If input character is greater than the tree character, take the right branch
- if (node[pos + (int)TernaryTreeByte.rightTree] == 0x0)
+ if (nodeBuffer[pos + (int)TernaryTreeByte.RightTree] == 0x0)
+ {
break;
- nodePos = nodePos + node[pos + (int)TernaryTreeByte.rightTree];
+ }
+
+ nodePos += nodeBuffer[pos + (int)TernaryTreeByte.RightTree];
}
else
{
// If input character is equal to the tree character, take the equal branch
if (charToFind == 0)
- return node[pos + (int)TernaryTreeByte.data];
+ {
+ return nodeBuffer[pos + (int)TernaryTreeByte.Data];
+ }
// The offset for the equal branch is always one
++nodePos;
// Move to the next input character
++stringPos;
+
if (stringPos == stringToFind.Length)
{
charToFind = 0;
@@ -99,13 +199,20 @@ public byte FindCaseInsensitiveString(string stringToFind)
else
{
charToFind = stringToFind[stringPos];
- if (charToFind > 'z') return 0; // Ternary tree only stores ASCII strings
- if (charToFind >= 'a') charToFind -= ('a' - 'A'); // Normalize to upper case
+
+ if (charToFind > 'z')
+ {
+ return 0; // Ternary tree only stores ASCII strings
+ }
+
+ if (charToFind >= 'a')
+ {
+ charToFind -= 'a' - 'A'; // Normalize to upper case
+ }
}
}
}
- // Return default
return 0;
}
}