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

Added Span support to Webencoders with direct encoding #338

Closed
wants to merge 8 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Microsoft.Extensions.Internal
#endif
static class WebEncoders
{
#if !NETCOREAPP2_1
#if !NETCOREAPP2_2 && !NETCOREAPP2_1
private const int MaxStackallocBytes = 256;
#endif
private const int MaxEncodedLength = (int.MaxValue / 4) * 3; // encode inflates the data by 4/3
Expand Down Expand Up @@ -251,7 +251,8 @@ public static unsafe string Base64UrlEncode(ReadOnlySpan<byte> data)

var base64Len = GetBufferSizeRequiredToBase64Encode(data.Length, out int numPaddingChars);
var base64UrlLen = base64Len - numPaddingChars;
#if NETCOREAPP2_1

#if NETCOREAPP2_2 || NETCOREAPP2_1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With dotnet/sdk#1813 this could be written cleaner.

fixed (byte* ptr = &MemoryMarshal.GetReference(data))
{
return string.Create(base64UrlLen, (Ptr: (IntPtr)ptr, data.Length), (base64Url, state) =>
Expand Down