Skip to content

Reduce converter string overhead in hot paths#17

Merged
nunoplopes merged 1 commit intomasterfrom
copilot/micro-optimizations-character-replacement
Apr 20, 2026
Merged

Reduce converter string overhead in hot paths#17
nunoplopes merged 1 commit intomasterfrom
copilot/micro-optimizations-character-replacement

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

This PR applies targeted micro-optimizations in the converter to reduce avoidable allocations/copies and use cheaper character APIs where applicable. Scope is intentionally narrow: no behavioral changes, only lower-overhead string handling.

  • Whitespace parsing: use char overloads

    • Replaced single-character string literals with character literals in trim logic to use the char overloads directly.
    • Affected code path: format width normalization in GetFmtArg.
  • Trait generation: avoid copying large string fragments

    • Updated ConvertOrdAndPartialOrdTraitsBase to accept std::string_view instead of owning std::string parameters.
    • This removes repeated by-value copies of prebuilt branch/return fragments during trait emission.
  • Code emission utility: reduce variadic argument copies

    • Updated Converter::_StrCat variadic parameters from pass-by-value to const&.
    • This avoids unnecessary temporary/string copies during high-frequency emission calls.
// Before
fmt_width.erase(0, fmt_width.find_first_not_of(" "));
fmt_width.erase(fmt_width.find_last_not_of(" ") + 1);

// After
fmt_width.erase(0, fmt_width.find_first_not_of(' '));
fmt_width.erase(fmt_width.find_last_not_of(' ') + 1);

Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/8c0eb26b-9b94-4eda-b871-1f2b17fe1aa4

Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
@nunoplopes nunoplopes marked this pull request as ready for review April 20, 2026 07:21
@nunoplopes nunoplopes merged commit eb9e570 into master Apr 20, 2026
17 checks passed
@nunoplopes nunoplopes deleted the copilot/micro-optimizations-character-replacement branch April 20, 2026 07:23
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.

2 participants