Use UnsafeAccessor in System.Runtime.Numerics.
#119846
Closed
+1,692
−1,719
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
With the introduction of
UnsafeAccessorTypeAttributein .NET 10 and later, methods of theNumberclass inSystem.Private.CoreLibcan now be called directly viaUnsafeAccessorAttribute. This allows replacing the previous implementations that relied onUtf8Char,Utf16Char, and similar types.Number.Unsafe.cs
Number.Unsafe.cs defines methods that are invoked from
System.Runtime.Numerics. Since these methods are not used withinSystem.Private.CoreLib, they must also be listed inILLink.Descriptors.Shared.xmlto prevent trimming.Because the internal
IUtfChar<TChar>interface cannot be accessed even withUnsafeAccessorAttribute, overloads forbyteandcharhave been added. In addition, since theNumberBufferref struct is defined separately but identically in bothSystem.Private.CoreLibandSystem.Runtime.Numerics, overloads usingvoid*have been added to enable access.The internal methods of
NumberFormatInfoare also accessed viaUnsafeAccessor.benchmark