-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Avoid some substring allocations during Uri host normalization #117289
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
Conversation
Tagging subscribers to this area: @dotnet/ncl |
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 reduces temporary string allocations during URI host normalization by introducing a span-based normalization helper and optimizing Bidi control character stripping.
- Introduces
NormalizeAndConcat
to normalize a span and concatenate it without intermediate allocations. - Refactors
StripBidiControlCharacters
to return a boolean and optional output, avoiding new strings when no characters are removed. - Updates
Uri.CheckAuthorityHelper
calls 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)
72988d1
to
e840bc0
Compare
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.
LGTM
Avoids 1 or 2 temporary string allocations - the argument to
Normalize
and (sometimes) its result.Only applies to Uris with non-ASCII values.