Skip to content

Commit 6732c66

Browse files
committed
remove some string copies
1 parent 839405d commit 6732c66

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,14 +1193,12 @@ void Unwrap(std::string &s, std::string_view prefix, std::string_view suffix) {
11931193
}
11941194
}
11951195

1196-
std::string ReplaceAll(std::string str, std::string_view from,
1197-
std::string_view to) {
1196+
void ReplaceAll(std::string &str, std::string_view from, std::string_view to) {
11981197
size_t pos = 0;
11991198
while ((pos = str.find(from, pos)) != std::string::npos) {
12001199
str.replace(pos, from.size(), to);
12011200
pos += to.size();
12021201
}
1203-
return str;
12041202
}
12051203

12061204
ConstCastType GetConstCastType(clang::QualType to, clang::QualType from) {

‎cpp2rust/converter/converter_lib.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ std::string_view Trim(std::string_view s);
230230

231231
void Unwrap(std::string &s, std::string_view prefix, std::string_view suffix);
232232

233-
std::string ReplaceAll(std::string str, std::string_view from,
234-
std::string_view to);
233+
void ReplaceAll(std::string &str, std::string_view from, std::string_view to);
235234

236235
enum class ConstCastType {
237236
ConstToConst,

‎cpp2rust/converter/mapper.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ std::string mapTypeStringRecursive(const std::string &cpp_type) {
619619
std::string normalizeTranslationRule(std::string rule) {
620620
// Detach pointer from double reference. Useful for matching translation
621621
// rules.
622-
rule = ReplaceAll(rule, "*&&", "* &&");
622+
ReplaceAll(rule, "*&&", "* &&");
623623

624624
const std::array<std::pair<std::regex, std::string>, 1> normalization_rules{{
625625
// Ignore constant template parameters, i.e. replace them with _.
@@ -832,7 +832,8 @@ std::string ToRustName(std::string name) {
832832
name[pos] = '_';
833833
++pos;
834834
}
835-
return ReplaceAll(name, "::", "_");
835+
ReplaceAll(name, "::", "_");
836+
return name;
836837
}
837838

838839
std::string ToString(clang::QualType qual_type, ScalarSugar sugar) {

‎cpp2rust/converter/plugins/emplace_back.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ clang::CXXConstructExpr *buildConstructExpr(clang::CXXMemberCallExpr *call,
137137
void Converter::emplace_back_emit_push_open(clang::CXXMemberCallExpr *call) {
138138
{
139139
PushExprKind push(*this, ExprKind::LValue);
140-
StrCat(ReplaceAll(ToString(call->getCallee()), "emplace_back", "push"));
140+
auto callee = ToString(call->getCallee());
141+
ReplaceAll(callee, "emplace_back", "push");
142+
StrCat(callee);
141143
}
142144
StrCat('(');
143145
}

0 commit comments

Comments
 (0)