Repository navigation
Avoid some substring allocations during Uri host normalization - #117289
Merged
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/ncl |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR reduces temporary string allocations during URI host normalization by introducing a span-based normalization helper and optimizing Bidi control character stripping.
- Introduces
NormalizeAndConcatto normalize a span and concatenate it without intermediate allocations. - Refactors
StripBidiControlCharactersto return a boolean and optional output, avoiding new strings when no characters are removed. - Updates
Uri.CheckAuthorityHelpercalls to use the new helpers.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Private.Uri/src/System/UriHelper.cs | Added NormalizeAndConcat and refactored StripBidiControlCharacters overloads for allocation improvements. |
| src/libraries/System.Private.Uri/src/System/Uri.cs | Updated host normalization logic to use NormalizeAndConcat and new StripBidiControlCharacters overloads. |
Comments suppressed due to low confidence (3)
src/libraries/System.Private.Uri/src/System/UriHelper.cs:23
- Add unit tests for NormalizeAndConcat to verify behavior with null start values, empty spans, and spans containing non-ASCII characters to ensure correct concatenation and normalization.
public static string NormalizeAndConcat(string? start, ReadOnlySpan<char> toNormalize)
src/libraries/System.Private.Uri/src/System/UriHelper.cs:610
- Add unit tests for the new StripBidiControlCharacters overloads to cover both the fast path (no removal) and removal path, including the backingString fallback behavior.
public static string StripBidiControlCharacters(ReadOnlySpan<char> strToClean, string? backingString = null)
src/libraries/System.Private.Uri/src/System/UriHelper.cs:23
- [nitpick] Consider adding XML documentation to NormalizeAndConcat to explain its purpose, expected parameters (including null handling), and behavior for consumers and future maintainers.
public static string NormalizeAndConcat(string? start, ReadOnlySpan<char> toNormalize)
MihaZupan
force-pushed
the
uri-normalizeAllocs
branch
from
July 3, 2025 20:43
72988d1 to
e840bc0
Compare
This was referenced Jul 4, 2025
MihaZupan
commented
Jul 4, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Avoids 1 or 2 temporary string allocations - the argument to
Normalizeand (sometimes) its result.Only applies to Uris with non-ASCII values.