-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Polyfill span Encoding APIs #120612
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
base: main
Are you sure you want to change the base?
Polyfill span Encoding APIs #120612
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes duplicated encoding fallback code that was forced to pin buffers for older target frameworks by introducing polyfills and utilizing the IncludeSpanPolyfills
property. The changes consolidate encoding operations to use modern span-based APIs consistently across all target frameworks.
Key changes:
- Removes custom span-to-pointer bridging code in favor of centralized polyfills
- Replaces custom
Utf8GetString
helper methods with directEncoding.UTF8.GetString
calls - Adds
IncludeSpanPolyfills=true
to project files that need encoding polyfills
Reviewed Changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
JsonWriterHelper.cs | Simplified UTF-8 encoding methods by removing manual buffer pinning |
ThrowHelper.cs | Replaced custom UTF-8 string conversion with standard encoding method |
JsonHelpers.cs | Removed custom Utf8GetString helper method and updated callers |
EncodingPolyfills.cs | Added centralized polyfills for span-based encoding APIs |
Directory.Build.targets | Added polyfills to the build system |
Various .csproj files | Enabled span polyfills for affected libraries |
src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.Text.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
if (bytes.Length == 0) | ||
{ | ||
charsWritten = 0; | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary or just an attempt at an optimization?
<PackageDescription>Provides support for some cryptographic primitives for .NET Framework and .NET Standard.</PackageDescription> | ||
<NoWarn>$(NoWarn);SYSLIB5006</NoWarn> | ||
<IncludeIndexRangeTypes>true</IncludeIndexRangeTypes> | ||
<IncludeSpanPolyfills>true</IncludeSpanPolyfills> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we running the trimmer on downlevel assemblies? If not, with this and the previous change, are we now adding some dead code to them?
Tagging subscribers to this area: @dotnet/area-meta |
{ | ||
if (chars.IsEmpty) | ||
{ | ||
// Ensure a non-null pointer is obtained, even though the expected answer is 0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most other places use a method called GetNonNullPinnableReference
to do this fixup
Removes a bunch of duplicated fallbacks that were forced to pin the buffers