Skip to content

Remove a few more instances of unsafe code in STJ - #114490

Merged
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:reduce-unsafe-stj-2
Apr 13, 2025
Merged

Remove a few more instances of unsafe code in STJ#114490
EgorBo merged 3 commits into
dotnet:mainfrom
EgorBo:reduce-unsafe-stj-2

Conversation

@EgorBo

@EgorBo EgorBo commented Apr 10, 2025

Copy link
Copy Markdown
Member

Follow up to #114154

With that, System.Text.Json.csproj (for net10 target) needs unsafe context only for two things:

  1. JavaScriptEncoder.FindFirstCharacterToEncode(char*, int) - filed an API proposal - [API Proposal]: TextEncoder.FindFirstCharacterToEncode(ReadOnlySpan<char>) #114423
  2. SkipLocalsInit requires AllowUnsafeBlocks. If we remove the attribute jit-diffs will look like this:
11755 : System.Text.Json.dasm (0.89 % of base)

(looks like mostly just inlined stackalloc zeroing)

Copilot AI review requested due to automatic review settings April 10, 2025 14:08
@ghost ghost added the area-System.Net label Apr 10, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comments suppressed due to low confidence (1)

src/libraries/Common/src/System/Text/ValueStringBuilder.cs:237

  • Removal of the unsafe Append overload is appropriate; ensure that all call sites have been updated to use the Append(ReadOnlySpan) overload so that functionality and performance are maintained.
public unsafe void Append(char* value, int length)

Comment thread src/libraries/System.Private.Uri/src/System/UriHelper.cs
Comment thread src/libraries/Common/src/System/HexConverter.cs
Comment thread src/libraries/Common/src/System/HexConverter.cs
{
return string.Create(bytes.Length * 2, (RosPtr: (IntPtr)(&bytes), casing), static (chars, args) =>
EncodeToUtf16(*(ReadOnlySpan<byte>*)args.RosPtr, chars, args.casing));
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will be removed once we stop building for net8.0 (this november?)

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

@EgorBo

EgorBo commented Apr 10, 2025

Copy link
Copy Markdown
Member Author

@stephentoub @eiriktsarpalis PTAL, a small follow up

@EgorBo EgorBo changed the title Remove a few more unsafe code from STJ Remove a few more instances of unsafe code in STJ Apr 11, 2025
@EgorBo
EgorBo merged commit 27b2548 into dotnet:main Apr 13, 2025
@EgorBo
EgorBo deleted the reduce-unsafe-stj-2 branch April 13, 2025 06:59
@github-actions github-actions Bot locked and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants