-
Notifications
You must be signed in to change notification settings - Fork 5k
Add APIs to BlobBuilder
for customizing the underlying byte array et al.
#115294
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?
Conversation
This commit introduces the `System.Text.Unicode.Utf8` type to the `Microsoft.Bcl.Memory` library. It includes type forwarding for `Utf8` in `Microsoft.Bcl.Memory.Forwards.cs`, updates the documentation in `PACKAGE.md` to include `Utf8` functionality, and adds corresponding test cases in `Microsoft.Bcl.Memory.Tests.csproj`. The documentation now emphasizes `Utf8` alongside `Index`, `Range`, and `Base64Url`, highlighting its role in converting data between UTF-8 and UTF-16 encodings.
Updated `PackageDescription` to include "Utf8" support. Added new `ItemGroup` for conditional compilation of UTF-8 and Unicode handling files for non-net8.0 frameworks. Modified visibility and implementations in `Ascii.Utility.Helpers.cs`, `Utf8.cs`, and `Utf8Utility` based on `MICROSOFT_BCL_MEMORY` define.
Updated `Microsoft.Bcl.Memory.Tests.csproj` to include `UnicodeUtility.cs` and removed .NET 8.0 targeting condition. Modified `Utf8Tests.cs` by adjusting using directives and enhancing the `DecodeHex` method with conditional compilation for .NET 5.0+.
Added a new property `<DefineConstants>$(DefineConstants);MICROSOFT_BCL_MEMORY</DefineConstants>` to the project file to define a new compilation constant for the project.
Co-authored-by: Theodore Tsirpanis <[email protected]>
- Added polyfill for System.Numerics.BitOperations for .NET Standard 2.0.
Removed the `DefineConstants` property from the project file, which included the constant `MICROSOFT_BCL_MEMORY`. This change may impact conditional compilation within the project.
For downlevel frameworks we add `Rune.cs` to `Microsoft.Bcl.Memory`. (cherry picked from commit 79ee05d)
(cherry picked from commit bf6f989)
(cherry picked from commit 445a232)
Co-authored-by: Jared Parsons <[email protected]>
And add more tests.
Note regarding the
|
1 similar comment
Note regarding the
|
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 adds new APIs to BlobBuilder for customizing the underlying byte array and updates related encoding and buffer-handling logic across metadata and core libraries. Key changes include replacing legacy UTF-8 encoding code with calls to the new System.Text.Unicode.Utf8 APIs, updating BlobBuilder’s API surface (including new constructors and properties), and adding NET-specific intrinsics support across several core modules.
Reviewed Changes
Copilot reviewed 31 out of 36 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
System/Reflection/Internal/Utilities/StreamExtensions.cs | Removed obsolete TryReadAll overload for Span to rely on newer API paths. |
System/Reflection/Internal/Utilities/BlobUtilities.cs | Rewrote WriteUtf8 to use Utf8.FromUtf16 for encoding, replacing manual UTF-8 encoding logic. |
System/Reflection/Metadata.cs | Added new BlobBuilder constructors, properties, and APIs including ReadOnlySpan/WriteBytes overloads. |
System.Private.CoreLib (various files) | Updated intrinsics and preprocessor conditions (#if NET, #if SYSTEM_PRIVATE_CORELIB) for newer vectorized and ASCII helper routines. |
Microsoft.Bcl.Memory (PACKAGE.md and others) | Updated documentation and type forwarding to include UTF-8 APIs for NET platforms. |
Files not reviewed (5)
- src/libraries/Microsoft.Bcl.Memory/src/Microsoft.Bcl.Memory.csproj: Language not supported
- src/libraries/Microsoft.Bcl.Memory/tests/Microsoft.Bcl.Memory.Tests.csproj: Language not supported
- src/libraries/System.Reflection.Metadata/System.Reflection.Metadata.sln: Language not supported
- src/libraries/System.Reflection.Metadata/src/Resources/Strings.resx: Language not supported
- src/libraries/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj: Language not supported
...braries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BlobUtilities.cs
Show resolved
Hide resolved
@@ -253,6 +258,7 @@ public void WriteBytes(byte[] buffer) { } | |||
public void WriteBytes(byte[] buffer, int start, int byteCount) { } | |||
public void WriteBytes(System.Collections.Immutable.ImmutableArray<byte> buffer) { } | |||
public void WriteBytes(System.Collections.Immutable.ImmutableArray<byte> buffer, int start, int byteCount) { } |
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.
[nitpick] The newly added WriteBytes(ReadOnlySpan) API lacks XML documentation. Adding a summary and usage notes would help API consumers understand its behavior and intended usage.
public void WriteBytes(System.Collections.Immutable.ImmutableArray<byte> buffer, int start, int byteCount) { } | |
public void WriteBytes(System.Collections.Immutable.ImmutableArray<byte> buffer, int start, int byteCount) { } | |
/// <summary> | |
/// Writes the contents of the specified <see cref="System.ReadOnlySpan{T}"/> of bytes to the current instance. | |
/// </summary> | |
/// <param name="buffer">The span of bytes to write.</param> | |
/// <remarks> | |
/// This method does not perform any validation on the contents of the buffer. | |
/// Ensure that the buffer contains valid data before calling this method. | |
/// </remarks> |
Copilot uses AI. Check for mistakes.
Tagging subscribers to this area: @dotnet/area-system-reflection-metadata |
Is this needed to introduce the new APIs? System.Text.Unicode.Utf8 change introduces a new dependency for System.Reflection.Metadata on .NET Framework that will be an extra work to push through the system. It would be better to avoid bundling the two changes together in a single PR. |
The other PR is approved and ready to merge #111292. After the merge and rebase this branch against main, those commits will disappear. |
The change that introduces System.Reflection.Metadata dependency on Microsoft.Bcl.Memory won't disappear. |
Note
Depends on #111292
Fixes #99244
Fixes #100418
This PR builds on top of @jaredpar's branch to add APIs for customizing the underlying buffer of a
BlobBuilder
. The chunking logic ofBlobBuilder
was updated to allocate multiple additional chunks with a user-customizable maximum size each. As part of this, we use APIs fromSystem.Text.Unicode.Utf8
to encode UTF-8 strings, which increases performance and safety, and reduces duplicate code.