Skip to content

Conversation

MihaZupan
Copy link
Member

Removes a bunch of duplicated fallbacks that were forced to pin the buffers

@MihaZupan MihaZupan added this to the 11.0.0 milestone Oct 10, 2025
@Copilot Copilot AI review requested due to automatic review settings October 10, 2025 20:25
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 10, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 direct Encoding.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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment on lines +117 to +121
if (bytes.Length == 0)
{
charsWritten = 0;
return true;
}
Copy link
Member

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>
Copy link
Member

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?

@teo-tsirpanis teo-tsirpanis added area-Meta and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 11, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

{
if (chars.IsEmpty)
{
// Ensure a non-null pointer is obtained, even though the expected answer is 0.
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants