Skip to content

Commit d24ce17

Browse files
authored
tokenize.cpp: avoid unnecessary copies with ScopeInfo3::addChild() (#7772)
1 parent 1219ae8 commit d24ce17

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/tokenize.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,8 +2385,8 @@ namespace {
23852385
std::set<std::string> recordTypes;
23862386
std::set<std::string> baseTypes;
23872387

2388-
ScopeInfo3 *addChild(Type scopeType, const std::string &scopeName, const Token *bodyStartToken, const Token *bodyEndToken) {
2389-
children.emplace_back(this, scopeType, scopeName, bodyStartToken, bodyEndToken);
2388+
ScopeInfo3 *addChild(Type scopeType, std::string scopeName, const Token *bodyStartToken, const Token *bodyEndToken) {
2389+
children.emplace_back(this, scopeType, std::move(scopeName), bodyStartToken, bodyEndToken);
23902390
return &children.back();
23912391
}
23922392

@@ -2534,19 +2534,19 @@ namespace {
25342534
scope = tok1->strAt(-3) + " :: " + scope;
25352535
tok1 = tok1->tokAt(-2);
25362536
}
2537-
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link());
2537+
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, std::move(scope), tok, tok->link());
25382538
added = true;
25392539
}
25402540
// inline member function
25412541
else if ((scopeInfo->type == ScopeInfo3::Record || scopeInfo->type == ScopeInfo3::Namespace) && tok1 && Token::Match(tok1->tokAt(-1), "%name% (")) {
2542-
const std::string scope = scopeInfo->name + "::" + tok1->strAt(-1);
2543-
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, scope, tok, tok->link());
2542+
std::string scope = scopeInfo->name + "::" + tok1->strAt(-1);
2543+
scopeInfo = scopeInfo->addChild(ScopeInfo3::MemberFunction, std::move(scope), tok, tok->link());
25442544
added = true;
25452545
}
25462546
}
25472547

25482548
if (!added)
2549-
scopeInfo = scopeInfo->addChild(ScopeInfo3::Other, emptyString, tok, tok->link());
2549+
scopeInfo = scopeInfo->addChild(ScopeInfo3::Other, "", tok, tok->link());
25502550
}
25512551
return;
25522552
}
@@ -2601,7 +2601,7 @@ namespace {
26012601
}
26022602

26032603
if (tok && tok->str() == "{") {
2604-
scopeInfo = scopeInfo->addChild(record ? ScopeInfo3::Record : ScopeInfo3::Namespace, classname, tok, tok->link());
2604+
scopeInfo = scopeInfo->addChild(record ? ScopeInfo3::Record : ScopeInfo3::Namespace, std::move(classname), tok, tok->link());
26052605
scopeInfo->baseTypes = std::move(baseTypes);
26062606
}
26072607
}

0 commit comments

Comments
 (0)