Skip to content

Use SearchValues for qualified-name separator scans#712

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-modernize-searchvalues
Jul 13, 2026
Merged

Use SearchValues for qualified-name separator scans#712
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-modernize-searchvalues

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Replaces the paired IndexOf("::") + IndexOf('.') (and LastIndexOf equivalents) separator scans with a single cached SearchValues<char> pass over { ':', '.' }.

In a qualified name a : only ever appears as part of a :: pair, so scanning for the single characters : and . is equivalent to scanning for the :: and . separators -- this collapses two passes into one and lets the shared SearchValues instance be created once. The matched-char check (: -> separator length 2, else 1) preserves the original separator length, so GetHashCode stays consistent with Equals.

Converted sites:

  • QualifiedNameComparer.GetHashCode (IndexOfAny)
  • The three LogPotentialTypedefRemappings diagnostic blocks in PInvokeGenerator.cs (LastIndexOfAny)

Single-character scans (e.g. IndexOf('*'), Split('\n'), Split(["::"]) on a substring) are intentionally left as-is since SearchValues<char> offers no benefit there.

This is behavior-preserving: generator output and comparer results are unchanged. Verified with a 0 warning/0 error Release build and the full golden test suite (3708 passed, 0 failed); no test expectations were touched.

Replace the paired `IndexOf("::")` + `IndexOf('.')` (and `LastIndexOf`
equivalents) separator scans with a single cached `SearchValues<char>`
pass over `{ ':', '.' }`.

In a qualified name a `:` only ever appears as part of a `::` pair, so
scanning for the single characters `:` and `.` is equivalent to scanning
for the `::` and `.` separators, while collapsing two passes into one and
letting the shared `SearchValues` instance be created once.

Converted sites:
- `QualifiedNameComparer.GetHashCode` (`IndexOfAny`)
- The three `LogPotentialTypedefRemappings` diagnostic blocks in
  `PInvokeGenerator.cs` (`LastIndexOfAny`)

Single-character scans (e.g. `IndexOf('*')`, `Split('\n')`, `Split(["::"])`
on a substring) are left as-is since `SearchValues<char>` offers no benefit.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 4317d43 into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding
tannergooding deleted the tannergooding-modernize-searchvalues branch July 13, 2026 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant