Skip to content

Use SearchValues/ContainsAny/span helpers in more places#67018

Open
MihaZupan wants to merge 13 commits into
mainfrom
copilot/replace-loops-with-searchvalues
Open

Use SearchValues/ContainsAny/span helpers in more places#67018
MihaZupan wants to merge 13 commits into
mainfrom
copilot/replace-loops-with-searchvalues

Conversation

@MihaZupan
Copy link
Copy Markdown
Member

I had Copilot look for more replaceable patterns, feel free to revert any where you don't think it matters.

Copilot AI and others added 12 commits June 2, 2026 22:23
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>
Copilot AI review requested due to automatic review settings June 4, 2026 11:54
@MihaZupan MihaZupan requested review from a team, BrennanConroy and halter73 as code owners June 4, 2026 11:54
@github-actions github-actions Bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 4, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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 with ContainsAny*, Count(...), CopyTo(...), and Clear() 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants