Avoid unnecessary heap allocations for short-lived strings#41
Merged
nunoplopes merged 4 commits intomasterfrom Apr 29, 2026
Merged
Avoid unnecessary heap allocations for short-lived strings#41nunoplopes merged 4 commits intomasterfrom
nunoplopes merged 4 commits intomasterfrom
Conversation
…tring copies Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/67031e6a-ec2f-4f6c-a534-ac63f300898d Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/67031e6a-ec2f-4f6c-a534-ac63f300898d Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
…ings Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/02bdd519-7825-4e67-90f0-8f2d0df2c427 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
nunoplopes
April 29, 2026 07:36
View session
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.
Several hot paths were heap-allocating temporary
std::stringobjects fromStringRef/SmallVectorsources only to immediately format or compare them.Changes
converter_refcount.cpp—getOpcodeStr().str()→std::string_viewfor binary opcode inConvertGenericBinaryOperatormapper.cpp—build_rust_type— replacestd::string(1, sign) + std::to_string(bits)(two allocations + concat) withstd::format("{}{}", sign, bits)mapper.cpp—ToStringunary opcode — replacestd::string opcode = getOpcodeStr().str()+ string concatenation withstd::string_view+std::formatconverter.cpp— enum emitter — eliminate intermediatestd::string init_str(init.begin(), init.end())by passingstd::string_viewviews directly tostd::formatconverter.cpp—GetOverloadedFunctionName—std::string name(decl->getNameAsString())→auto name(removes redundant copy-construction)converter.cpp— enum constant formatting —getName().str()→std::string_view(getName())Example before/after for the enum value emitter: