[SRM] Miscellaneous clean-up.#127308
Merged
jkotas merged 11 commits intodotnet:mainfrom Apr 24, 2026
Merged
Conversation
…UTF8.GetByteCount`.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR performs a set of small cleanups in System.Reflection.Metadata, primarily simplifying internal helpers and reducing custom/unsafe code paths.
Changes:
- Simplifies PE header/stub writing and embedded PDB decompression code paths.
- Reduces custom UTF-8 helper usage by switching several call sites to
Encoding.UTF8/charAPIs. - Consolidates
EncodingHelperimplementation and removes unused internal APIs/tests (e.g.,Hash.Combine(bool, …)and related test).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Reflection.Metadata/tests/Utilities/HashTests.cs | Removes test for deleted Hash.Combine(bool, int) overload. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEReader.EmbeddedPortablePdb.cs | Uses Stream.ReadAtLeast on .NET builds instead of a custom TryReadAll(Span<byte>) helper. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEHeaderBuilder.cs | Computes header size from PEBuilder.DosHeader.Length rather than a separate constant. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/PEBuilder.cs | Simplifies DOS stub write path and removes DosHeaderSize constant. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/MetadataReader.cs | Changes GetBlobContent to request non-unique blob bytes. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Internal/BlobHeap.cs | Adds unique option to GetBytes and threads it through virtual blob handling. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/IL/MethodBodyBlock.cs | Uses ImmutableArray builder + MoveToImmutable() for exception region reading. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/PortablePdbBuilder.cs | Switches UTF-8 byte count assert to Encoding.UTF8. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataRootBuilder.cs | Uses Encoding.UTF8.GetByteCount instead of BlobUtilities.GetUTF8ByteCount(string). |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.Heaps.cs | Replaces custom surrogate helpers/UTF-8 byte count with char/Encoding.UTF8 APIs in string heap serialization logic. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/BlobWriter.cs | Uses Encoding.UTF8.GetByteCount(char*, int) when calculating UTF-8 write size. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/StreamExtensions.cs | Removes .NET-only TryReadAll(Span<byte>) overload. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/Hash.cs | Removes unused Hash.Combine(bool, int) overload. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EncodingHelper.netcoreapp.cs | Deletes the netcoreapp-specific implementation. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/EncodingHelper.cs | Consolidates implementation and switches to ArrayPool<byte>.Shared for prefixed decoding. |
| src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/BlobUtilities.cs | Replaces custom surrogate helpers with char APIs and removes GetUTF8ByteCount(string) helper. |
| src/libraries/System.Reflection.Metadata/src/System.Reflection.Metadata.csproj | Consolidates EncodingHelper compile include and removes conditional file inclusion; also normalizes the project file header. |
jkotas
approved these changes
Apr 23, 2026
This was referenced Apr 23, 2026
Open
MihaZupan
approved these changes
Apr 23, 2026
Not necessary since dotnet#126924.
Member
|
/ba-g Known issue #127341 that has been fixed in main already |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR contains various small changes to
System.Reflection.Metadatathat have been noticed since some time, some of which being cherry-picked from #115294, to reduce its scope.