Use char overloads for single-char string operations - #12922
Merged
Conversation
Replace StartsWith/EndsWith/IndexOf calls that take a single-character string and StringComparison.Ordinal with the equivalent char overloads. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
Updated @niksedk |
7 tasks
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.
Summary
StartsWith/EndsWith/IndexOfcalls taking a single-character string plusStringComparison.Ordinalwith the equivalentcharoverloads (e.g.s.EndsWith("\"", StringComparison.Ordinal)→s.EndsWith('"'))Benchmarks
BenchmarkDotNet 0.14.0, .NET 10, Release,
[MemoryDiagnoser], 15 iterations per build — this branch vs parent commit 2131a6b, exercising the changed methods and an aggregate round-trip over the 20 changed subtitle formats (100-paragraph subtitle; 19 exercisable viaToText, 18 viaLoadSubtitle):Utilities.ReverseStartAndEndingForRightToLeftMoveWordUpDown.MoveWordUpMoveWordUpDown.MoveWordDownContinuationUtilities.IsFullLineTagLoadSubtitle(aggregate)RemoveTextForHI.RemoveTextFromHearImpairedToText(aggregate)Formatting.SetTagsAndReturnTrimmed+ReAddFormattingAllocations are byte-identical on every benchmark, as expected — the char overloads change comparison cost, not allocation. Every benchmark moved in the same direction (4–16% faster); the small per-call savings compound because these calls sit inside per-line/per-character parsing loops.
Test plan
dotnet test tests/libse/LibSETests.csprojpasses (745/745 locally)dotnet test tests/UI/UITests.csprojpasses (913 passed, 1 skipped locally)dotnet test tests/libuilogic/LibUiLogicTests.csprojpasses (18/18 locally)🤖 Generated with Claude Code