Skip to content

Commit 22a3007

Browse files
Copilotnunoplopes
andauthored
Simplify StrCat specialization: remove if constexpr branch
All N values (including N==2) now use _MakeStringWithSpace to create a combined string+space buffer and perform a single append call. This is cleaner and avoids the two-operation path for single-char literals too. Agent-Logs-Url: https://github.com/Cpp2Rust/cpp2rust/sessions/3ee80ab3-b415-4172-90d7-3a80ee9aa747 Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
1 parent d4c81a4 commit 22a3007

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

cpp2rust/converter/converter.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,15 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
336336
rs_code += ' ';
337337
}
338338

339-
// Specialization for string literals (const char[N]):
340-
// - N == 2 (single char, e.g. "("): use character append rather than string
341-
// append to avoid a strlen scan.
342-
// - N > 2 (longer string): combine the string and trailing space into one
343-
// contiguous buffer and append it in a single call.
339+
// Specialization for string literals (const char[N]): combines the string
340+
// content and a trailing space into a single contiguous buffer (using the
341+
// compile-time size N to skip any strlen scan) and appends it in one call.
342+
// This covers all lengths, including single-char literals such as "(".
344343
template <std::size_t N>
345344
static void AppendToCode(std::string &rs_code, const char (&val)[N]) {
346-
if constexpr (N == 2) {
347-
rs_code += val[0];
348-
rs_code += ' ';
349-
} else {
350-
const auto combined =
351-
_MakeStringWithSpace(val, std::make_index_sequence<N - 1>{});
352-
rs_code.append(combined.data(), N);
353-
}
345+
const auto combined =
346+
_MakeStringWithSpace(val, std::make_index_sequence<N - 1>{});
347+
rs_code.append(combined.data(), N);
354348
}
355349

356350
class Buffer {

0 commit comments

Comments
 (0)