Skip to content

Use char overloads for single-char string operations - #12922

Merged
niksedk merged 1 commit into
SubtitleEdit:mainfrom
ivandrofly:use-char-overloads
Jul 29, 2026
Merged

Use char overloads for single-char string operations#12922
niksedk merged 1 commit into
SubtitleEdit:mainfrom
ivandrofly:use-char-overloads

Conversation

@ivandrofly

@ivandrofly ivandrofly commented Jul 28, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace StartsWith/EndsWith/IndexOf calls taking a single-character string plus StringComparison.Ordinal with the equivalent char overloads (e.g. s.EndsWith("\"", StringComparison.Ordinal)s.EndsWith('"'))
  • Pure refactor across 31 files in libse, ui, and tests — no behavior change

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 via ToText, 18 via LoadSubtitle):

Benchmark Time before Time after Change
Utilities.ReverseStartAndEndingForRightToLeft 623.7 ns 525.8 ns −16%
MoveWordUpDown.MoveWordUp 265.8 ns 235.8 ns −11%
MoveWordUpDown.MoveWordDown 438.4 ns 395.1 ns −10%
ContinuationUtilities.IsFullLineTag 3.39 µs 3.11 µs −8%
All 18 formats LoadSubtitle (aggregate) 19.05 ms 17.46 ms −8%
RemoveTextForHI.RemoveTextFromHearImpaired 6.31 µs 5.86 µs −7%
All 19 formats ToText (aggregate) 2.32 ms 2.19 ms −6%
Formatting.SetTagsAndReturnTrimmed + ReAddFormatting 772.9 ns 739.1 ns −4%

Allocations 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.csproj passes (745/745 locally)
  • dotnet test tests/UI/UITests.csproj passes (913 passed, 1 skipped locally)
  • dotnet test tests/libuilogic/LibUiLogicTests.csproj passes (18/18 locally)
  • Load a SAMI/JSON/CSV subtitle file and confirm parsing is unchanged

🤖 Generated with Claude Code

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>
@ivandrofly

Copy link
Copy Markdown
Member Author

Updated @niksedk

@niksedk
niksedk merged commit a3521fd into SubtitleEdit:main Jul 29, 2026
1 check passed
@ivandrofly
ivandrofly deleted the use-char-overloads branch July 29, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants