Use SearchValues/ContainsAny/span helpers in more places#67018
Open
MihaZupan wants to merge 13 commits into
Open
Use SearchValues/ContainsAny/span helpers in more places#67018MihaZupan wants to merge 13 commits into
MihaZupan wants to merge 13 commits into
Conversation
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…rightExtensions HashSet to SearchValues Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…e AsSpan Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…ody HasInvalidPathChars Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
…rt two more IndexOfAny-style checks Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
… helpers Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
This reverts commit 9bffe7d. Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Co-authored-by: MihaZupan <25307628+MihaZupan@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR applies a set of low-risk micro-refactors across shared infrastructure and middleware/components code to use newer SearchValues<T>, ContainsAny* helpers, and span-based APIs, with the goal of improving readability and (in some cases) performance via vectorized implementations.
Changes:
- Replaced several
IndexOfAny*/ manual-loop patterns withContainsAny*,Count(...),CopyTo(...), andClear()span helpers. - Introduced
HttpRuleParser.IsToken(...)and updated token validations to use it consistently. - Switched a few small char-set definitions to
SearchValues<char>(with conditional compilation where multi-targeting requires it).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/ServerInfrastructure/HttpCharacters.cs | Uses ContainsAnyExcept for authority validation against SearchValues<byte>. |
| src/Shared/HttpRuleParser.cs | Adds IsToken(...) helper based on ContainsAnyExcept(TokenChars). |
| src/Servers/Kestrel/shared/PooledStreamStack.cs | Replaces element-shifting/clearing loops with span CopyTo + Clear. |
| src/Mvc/Mvc.TagHelpers/src/GlobbingUrlBuilder.cs | Uses SearchValues<char> + Contains for HTML attribute whitespace checks. |
| src/Middleware/ResponseCaching/src/ResponseCachingKeyProvider.cs | Uses ContainsAny for delimiter detection. |
| src/Middleware/OutputCaching/src/OutputCacheKeyProvider.cs | Uses ContainsAny for delimiter detection. |
| src/Middleware/HttpOverrides/src/ForwardedHeadersMiddleware.cs | Uses ContainsAnyExcept* span helpers for scheme/port validation. |
| src/Http/Routing/src/Patterns/RoutePatternParser.cs | Uses ContainsAny for invalid parameter name character detection. |
| src/Http/Routing/src/Patterns/RoutePatternFactory.cs | Uses ContainsAny for invalid parameter name character detection. |
| src/Http/Routing/src/PathTokenizer.cs | Uses span Count('/') to compute segment count. |
| src/Http/Headers/src/HeaderUtilities.cs | Uses HttpRuleParser.IsToken and span Count for quoted-string escaping. |
| src/Http/Headers/src/CookieHeaderValue.cs | Uses HttpRuleParser.IsToken for cookie name validation. |
| src/Http/Headers/src/ContentDispositionHeaderValue.cs | Uses IsToken, ContainsAny, and ContainsAnyExceptInRange helpers. |
| src/FileProviders/Embedded/src/Manifest/EmbeddedFilesManifest.cs | Uses SearchValues<char> for invalid path char search when NET8_0_OR_GREATER. |
| src/FileProviders/Embedded/src/EmbeddedFileProvider.cs | Uses SearchValues<char> for invalid path char search when NET8_0_OR_GREATER. |
| src/Components/Web/src/Forms/Mapping/FormMappingError.cs | Simplifies separator search using LastIndexOfAny('.', '['). |
| src/Components/Web/src/Forms/FieldIdGenerator.cs | Uses ContainsAny(InvalidIdChars) for the fast-path check. |
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.
I had Copilot look for more replaceable patterns, feel free to revert any where you don't think it matters.