Skip to content

Commit 6bc7f33

Browse files
Copilotnunoplopes
andauthored
Append single char + space as one 2-byte call in _AppendRuns
Add a char-specific overload of _AppendRuns (more specialized than the generic const T& overload by partial ordering) that flushes any pending literal buffer, then appends the char value and its trailing space as a single rs_code.append(pair, 2) call instead of two separate += operations. Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/c9bd1adc-01f6-415e-a50c-9e8a4cb1e414 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent 26e56b6 commit 6bc7f33

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

cpp2rust/converter/converter.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
361361
_AppendRuns(rs_code, std::array<char, 0>{}, rest...);
362362
}
363363

364+
// Head is a single char: flush the pending buffer (if any), then append
365+
// the char and its trailing space together as a single 2-byte append.
366+
template <std::size_t BufSize, typename... Rest>
367+
static void _AppendRuns(std::string &rs_code, std::array<char, BufSize> buf,
368+
char val, const Rest &...rest) {
369+
if constexpr (BufSize > 0)
370+
rs_code.append(buf.data(), BufSize);
371+
const char pair[2] = {val, ' '};
372+
rs_code.append(pair, 2);
373+
_AppendRuns(rs_code, std::array<char, 0>{}, rest...);
374+
}
375+
364376
class Buffer {
365377
std::string partial_code;
366378
std::string *full_code;

0 commit comments

Comments
 (0)