Skip to content

Commit

Permalink
Remove unsafe quirks from System.Text.Encodings.Web
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Nov 17, 2024
1 parent 96ae7cf commit 452857b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 345 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ internal override int EncodeUtf8(Rune value, Span<byte> destination)
{
if (value.Value == '<')
{
if (!SpanUtility.TryWriteBytes(destination, (byte)'&', (byte)'l', (byte)'t', (byte)';')) { goto OutOfSpace; }
if (!"&lt;"u8.TryCopyTo(destination)) { goto OutOfSpace; }
return 4;
}
else if (value.Value == '>')
{
if (!SpanUtility.TryWriteBytes(destination, (byte)'&', (byte)'g', (byte)'t', (byte)';')) { goto OutOfSpace; }
if (!"&gt;"u8.TryCopyTo(destination)) { goto OutOfSpace; }
return 4;
}
else if (value.Value == '&')
{
if (!SpanUtility.TryWriteBytes(destination, (byte)'&', (byte)'a', (byte)'m', (byte)'p', (byte)';')) { goto OutOfSpace; }
if (!"&amp;"u8.TryCopyTo(destination)) { goto OutOfSpace; }
return 5;
}
else if (value.Value == '\"')
{
if (!SpanUtility.TryWriteBytes(destination, (byte)'&', (byte)'q', (byte)'u', (byte)'o', (byte)'t', (byte)';')) { goto OutOfSpace; }
if (!"&quot;"u8.TryCopyTo(destination)) { goto OutOfSpace; }
return 6;
}
else
Expand All @@ -109,7 +109,7 @@ static int TryEncodeScalarAsHex(object @this, uint scalarValue, Span<byte> desti
if (!SpanUtility.IsValidIndex(destination, idxOfSemicolon)) { goto OutOfSpaceInner; }
destination[idxOfSemicolon] = (byte)';';

if (!SpanUtility.TryWriteBytes(destination, (byte)'&', (byte)'#', (byte)'x', (byte)'0'))
if (!"&#x0"u8.TryCopyTo(destination))
{
Debug.Fail("We should've had enough room to write 4 bytes.");
}
Expand All @@ -134,22 +134,22 @@ internal override int EncodeUtf16(Rune value, Span<char> destination)
{
if (value.Value == '<')
{
if (!SpanUtility.TryWriteChars(destination, '&', 'l', 't', ';')) { goto OutOfSpace; }
if (!"&lt;".TryCopyTo(destination)) { goto OutOfSpace; }

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 137 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L137

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(137,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
return 4;
}
else if (value.Value == '>')
{
if (!SpanUtility.TryWriteChars(destination, '&', 'g', 't', ';')) { goto OutOfSpace; }
if (!"&gt;".TryCopyTo(destination)) { goto OutOfSpace; }

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 142 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L142

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(142,33): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
return 4;
}
else if (value.Value == '&')
{
if (!SpanUtility.TryWriteChars(destination, '&', 'a', 'm', 'p', ';')) { goto OutOfSpace; }
if (!"&amp;".TryCopyTo(destination)) { goto OutOfSpace; }

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 147 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L147

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(147,34): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
return 5;
}
else if (value.Value == '\"')
{
if (!SpanUtility.TryWriteChars(destination, '&', 'q', 'u', 'o', 't', ';')) { goto OutOfSpace; }
if (!"&quot;".TryCopyTo(destination)) { goto OutOfSpace; }

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 152 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L152

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(152,35): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
return 6;
}
else
Expand Down Expand Up @@ -186,7 +186,7 @@ static int TryEncodeScalarAsHex(object @this, uint scalarValue, Span<char> desti

// It's more efficient to write 4 chars at a time instead of 1 char.
// The '0' at the end will be overwritten.
if (!SpanUtility.TryWriteChars(destination, '&', '#', 'x', '0'))
if ("&#x0".TryCopyTo(destination))

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Mono_MiniJIT_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Check failure on line 189 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs#L189

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/DefaultHtmlEncoder.cs(189,32): error CS1061: (NETCORE_ENGINEERING_TELEMETRY=Build) 'string' does not contain a definition for 'TryCopyTo' and no accessible extension method 'TryCopyTo' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
{
Debug.Fail("We should've had enough room to write 4 chars.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,236 +24,18 @@ public static bool IsValidIndex<T>(Span<T> span, int index)
return ((uint)index < (uint)span.Length) ? true : false;
}

/// <summary>
/// Tries writing four bytes to the span. If success, returns true. If the span is not large
/// enough to hold four bytes, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteBytes(Span<byte> span, byte a, byte b, byte c, byte d)
{
if (span.Length >= 4)
{
uint abcd32;
if (BitConverter.IsLittleEndian)
{
abcd32 = ((uint)d << 24) | ((uint)c << 16) | ((uint)b << 8) | a;
}
else
{
abcd32 = ((uint)a << 24) | ((uint)b << 16) | ((uint)c << 8) | d;
}
Unsafe.WriteUnaligned<uint>(ref MemoryMarshal.GetReference(span), abcd32);
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing five bytes to the span. If success, returns true. If the span is not large
/// enough to hold five bytes, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteBytes(Span<byte> span, byte a, byte b, byte c, byte d, byte e)
{
if (span.Length >= 5)
{
uint abcd32;
if (BitConverter.IsLittleEndian)
{
abcd32 = ((uint)d << 24) | ((uint)c << 16) | ((uint)b << 8) | a;
}
else
{
abcd32 = ((uint)a << 24) | ((uint)b << 16) | ((uint)c << 8) | d;
}
ref byte rDest = ref MemoryMarshal.GetReference(span);
Unsafe.WriteUnaligned<uint>(ref rDest, abcd32);
Unsafe.Add(ref rDest, 4) = e;
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing six bytes to the span. If success, returns true. If the span is not large
/// enough to hold six bytes, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteBytes(Span<byte> span, byte a, byte b, byte c, byte d, byte e, byte f)
{
if (span.Length >= 6)
{
uint abcd32;
uint ef16;
if (BitConverter.IsLittleEndian)
{
abcd32 = ((uint)d << 24) | ((uint)c << 16) | ((uint)b << 8) | a;
ef16 = ((uint)f << 8) | e;
}
else
{
abcd32 = ((uint)a << 24) | ((uint)b << 16) | ((uint)c << 8) | d;
ef16 = ((uint)e << 8) | f;
}
ref byte rDest = ref MemoryMarshal.GetReference(span);
Unsafe.WriteUnaligned<uint>(ref rDest, abcd32);
Unsafe.WriteUnaligned<ushort>(ref Unsafe.Add(ref rDest, 4), (ushort)ef16);
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing four chars to the span. If success, returns true. If the span is not large
/// enough to hold four chars, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteChars(Span<char> span, char a, char b, char c, char d)
{
if (span.Length >= 4)
{
ulong abcd64;
if (BitConverter.IsLittleEndian)
{
abcd64 = ((ulong)d << 48) | ((ulong)c << 32) | ((ulong)b << 16) | a;
}
else
{
abcd64 = ((ulong)a << 48) | ((ulong)b << 32) | ((ulong)c << 16) | d;
}
Unsafe.WriteUnaligned<ulong>(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(span)), abcd64);
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing five chars to the span. If success, returns true. If the span is not large
/// enough to hold five chars, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteChars(Span<char> span, char a, char b, char c, char d, char e)
{
if (span.Length >= 5)
{
ulong abcd64;
if (BitConverter.IsLittleEndian)
{
abcd64 = ((ulong)d << 48) | ((ulong)c << 32) | ((ulong)b << 16) | a;
}
else
{
abcd64 = ((ulong)a << 48) | ((ulong)b << 32) | ((ulong)c << 16) | d;
}
ref char rDest = ref MemoryMarshal.GetReference(span);
Unsafe.WriteUnaligned<ulong>(ref Unsafe.As<char, byte>(ref rDest), abcd64);
Unsafe.Add(ref rDest, 4) = e;
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing six chars to the span. If success, returns true. If the span is not large
/// enough to hold six chars, leaves the span unchanged and returns false.
/// </summary>
/// <remarks>
/// Parameters are intended to be constant values.
/// </remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteChars(Span<char> span, char a, char b, char c, char d, char e, char f)
{
if (span.Length >= 6)
{
ulong abcd64;
uint ef32;
if (BitConverter.IsLittleEndian)
{
abcd64 = ((ulong)d << 48) | ((ulong)c << 32) | ((ulong)b << 16) | a;
ef32 = ((uint)f << 16) | e;
}
else
{
abcd64 = ((ulong)a << 48) | ((ulong)b << 32) | ((ulong)c << 16) | d;
ef32 = ((uint)e << 16) | f;
}
ref byte rDest = ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(span));
Unsafe.WriteUnaligned<ulong>(ref rDest, abcd64);
Unsafe.WriteUnaligned<uint>(ref Unsafe.AddByteOffset(ref rDest, (nint)sizeof(ulong)), ef32);
return true;
}
else
{
return false;
}
}

/// <summary>
/// Tries writing a 64-bit value as little endian to the span. If success, returns true. If
/// the span is not large enough to hold 8 bytes, leaves the span unchanged and returns false.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool TryWriteUInt64LittleEndian(Span<byte> span, int offset, ulong value)
{
if (AreValidIndexAndLength(span.Length, offset, sizeof(ulong)))
{
if (!BitConverter.IsLittleEndian)
{
value = BinaryPrimitives.ReverseEndianness(value);
}
Unsafe.WriteUnaligned<ulong>(ref Unsafe.Add(ref MemoryMarshal.GetReference(span), (nint)(uint)offset), value);
return true;
}
else
{
return false;
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool AreValidIndexAndLength(int spanRealLength, int requestedOffset, int requestedLength)
{
// Logic here is copied from Span<T>.Slice.
if (IntPtr.Size == 4)
{
if ((uint)requestedOffset > (uint)spanRealLength) { return false; }
if ((uint)requestedLength > (uint)(spanRealLength - requestedOffset)) { return false; }
}
else
if (!BitConverter.IsLittleEndian)
{
if ((ulong)(uint)spanRealLength < (ulong)(uint)requestedOffset + (ulong)(uint)requestedLength) { return false; }
value = BinaryPrimitives.ReverseEndianness(value);
}
return true;
return MemoryMarshal.TryWrite(span.Slice(offset), value);

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug Mono_Interpreter_LibrariesTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux_musl-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-arm64 Debug Libraries_CheckedCoreCLR)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build linux-x64 Debug CoreCLR_Libraries)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword

Check failure on line 38 in src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs

View check run for this annotation

Azure Pipelines / runtime (Build browser-wasm linux Release LibraryTests_EAT)

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs#L38

src/libraries/System.Text.Encodings.Web/src/System/Text/Encodings/Web/SpanUtility.cs(38,63): error CS1620: (NETCORE_ENGINEERING_TELEMETRY=Build) Argument 2 must be passed with the 'ref' keyword
}
}
}
Loading

0 comments on commit 452857b

Please sign in to comment.