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

use new System.Text.Ascii APIs, remove internal helpers #48368

Merged
merged 5 commits into from
Jul 17, 2023
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
2 changes: 1 addition & 1 deletion src/Http/Headers/src/ContentDispositionHeaderValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ private static string Encode5987(StringSegment input)
int totalBytesConsumed = 0;
while (totalBytesConsumed < inputBytes.Length)
{
if (inputBytes[totalBytesConsumed] <= 0x7F)
if (Ascii.IsValid(inputBytes[totalBytesConsumed]))
{
// This is an ASCII char. Let's handle it ourselves.

Expand Down
73 changes: 0 additions & 73 deletions src/Http/Routing/src/Matching/Ascii.cs

This file was deleted.

3 changes: 2 additions & 1 deletion src/Http/Routing/src/Matching/JumpTableBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text;

namespace Microsoft.AspNetCore.Routing.Matching;

Expand Down Expand Up @@ -42,7 +43,7 @@ public static JumpTable Build(int defaultDestination, int exitDestination, (stri

// The IL Emit jump table is not faster for a single entry - but we have an optimized version when all text
// is ASCII
if (pathEntries.Length == 1 && Ascii.IsAscii(pathEntries[0].text))
if (pathEntries.Length == 1 && Ascii.IsValid(pathEntries[0].text))
{
var entry = pathEntries[0];
return new SingleEntryAsciiJumpTable(defaultDestination, exitDestination, entry.text, entry.destination);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Text;

namespace Microsoft.AspNetCore.Routing.Matching;

// Optimized implementation for cases where we know that we're
Expand Down Expand Up @@ -41,7 +44,9 @@ public override int GetDestination(string path, PathSegment segment)
var a = path.AsSpan(segment.Start, length);
var b = text.AsSpan();

return Ascii.AsciiIgnoreCaseEquals(a, b, length) ? _destination : _defaultDestination;
Debug.Assert(a.Length == b.Length && b.Length == length);

return Ascii.EqualsIgnoreCase(a, b) ? _destination : _defaultDestination;
}

public override string DebuggerToString()
Expand Down
110 changes: 0 additions & 110 deletions src/Http/Routing/test/UnitTests/Matching/AsciiTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ private static ulong GetAsciiStringAsLong(string str)
{
Debug.Assert(str.Length == 8, "String must be exactly 8 (ASCII) characters long.");

var bytes = Encoding.ASCII.GetBytes(str);
Span<byte> bytes = stackalloc byte[8];
OperationStatus operationStatus = Ascii.FromUtf16(str, bytes, out _);

Debug.Assert(operationStatus == OperationStatus.Done);

return BinaryPrimitives.ReadUInt64LittleEndian(bytes);
}
Expand All @@ -63,7 +66,11 @@ private static uint GetAsciiStringAsInt(string str)
{
Debug.Assert(str.Length == 4, "String must be exactly 4 (ASCII) characters long.");

var bytes = Encoding.ASCII.GetBytes(str);
Span<byte> bytes = stackalloc byte[4];
OperationStatus operationStatus = Ascii.FromUtf16(str, bytes, out _);

Debug.Assert(operationStatus == OperationStatus.Done);

return BinaryPrimitives.ReadUInt32LittleEndian(bytes);
}

Expand Down
Loading
Loading