Skip to content

Commit c7311b0

Browse files
committed
avoid some unnecessary copies
1 parent 2f9fbfd commit c7311b0

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

simplecpp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,8 +1680,8 @@ namespace simplecpp {
16801680
};
16811681
private:
16821682
/** Create new token where Token::macro is set for replaced tokens */
1683-
Token *newMacroToken(const TokenString &str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const {
1684-
Token *tok = new Token(str,loc);
1683+
Token *newMacroToken(TokenString str, const Location &loc, bool replaced, const Token *expandedFromToken=nullptr) const {
1684+
Token *tok = new Token(std::move(str),loc);
16851685
if (replaced)
16861686
tok->macro = nameTokDef->str();
16871687
if (expandedFromToken)
@@ -2300,7 +2300,7 @@ namespace simplecpp {
23002300
output->takeTokens(tokensB);
23012301
} else if (sameline(B, nextTok) && sameline(B, nextTok->next) && nextTok->op == '#' && nextTok->next->op == '#') {
23022302
TokenList output2(files);
2303-
output2.push_back(new Token(strAB, tok->location));
2303+
output2.push_back(new Token(std::move(strAB), tok->location));
23042304
nextTok = expandHashHash(&output2, loc, nextTok, macros, expandedmacros, parametertokens);
23052305
output->deleteToken(A);
23062306
output->takeTokens(output2);
@@ -3455,7 +3455,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
34553455
hdr += tok->str();
34563456
}
34573457
inc2.clear();
3458-
inc2.push_back(new Token(hdr, inc1.cfront()->location));
3458+
inc2.push_back(new Token(std::move(hdr), inc1.cfront()->location));
34593459
inc2.front()->op = '<';
34603460
}
34613461

@@ -3615,7 +3615,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
36153615
E += (E.empty() ? "" : " ") + tok->str();
36163616
const long long result = evaluate(expr, dui, sizeOfType);
36173617
conditionIsTrue = (result != 0);
3618-
ifCond->push_back(IfCond(rawtok->location, E, result));
3618+
ifCond->push_back(IfCond(rawtok->location, std::move(E), result));
36193619
} else {
36203620
const long long result = evaluate(expr, dui, sizeOfType);
36213621
conditionIsTrue = (result != 0);
@@ -3711,7 +3711,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
37113711
else if (output.back())
37123712
output.back()->setstr(output.cback()->str() + s);
37133713
else
3714-
output.push_back(new Token(s, loc));
3714+
output.push_back(new Token(std::move(s), loc));
37153715
} else {
37163716
output.takeTokens(tokens);
37173717
}

test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,11 +3083,11 @@ static void stdValid()
30833083
outputList.clear();
30843084
}
30853085

3086-
static void assertToken(const std::string& s, bool name, bool number, bool comment, char op, int line)
3086+
static void assertToken(std::string s, bool name, bool number, bool comment, char op, int line)
30873087
{
30883088
const std::vector<std::string> f;
30893089
const simplecpp::Location l(f);
3090-
const simplecpp::Token t(s, l);
3090+
const simplecpp::Token t(std::move(s), l);
30913091
assertEquals(name, t.name, line);
30923092
assertEquals(number, t.number, line);
30933093
assertEquals(comment, t.comment, line);

0 commit comments

Comments
 (0)