Repository navigation
Use SearchValues/ContainsAny/span helpers in more places - #67018
Merged
Merged
Conversation
Co-authored-by: MihaZupan <[email protected]>
…rightExtensions HashSet to SearchValues Co-authored-by: MihaZupan <[email protected]>
…e AsSpan Co-authored-by: MihaZupan <[email protected]>
…ody HasInvalidPathChars Co-authored-by: MihaZupan <[email protected]>
…rt two more IndexOfAny-style checks Co-authored-by: MihaZupan <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
… helpers Co-authored-by: MihaZupan <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
This reverts commit 9bffe7d. Co-authored-by: MihaZupan <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
Co-authored-by: MihaZupan <[email protected]>
MihaZupan
requested review from
a team,
BrennanConroy and
halter73
as code owners
June 4, 2026 11:54
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. |
BrennanConroy
approved these changes
Jun 11, 2026
martincostello
added a commit
to martincostello/aspnetcore
that referenced
this pull request
Jun 11, 2026
Revert overlapping changes with dotnet#67018.
maraf
approved these changes
Jun 24, 2026
javiercn
approved these changes
Jun 24, 2026
Member
|
/ba-g unrelated |
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.