QUrl: move intro string passed by value

Amends commit 31207b539a19182b48c4b3b8413190d505633eea.

Unlike the other setXxx() functions, setUserInfo() has a trimmed() call,
which was retained from Qt 4's QUrl. This is probably wrong, but no one
has complained in the 17 years of public Git history. As a result, the
template function QUrlPrivate::setUserInfo() was getting a copy of the
string, which is inefficient. We can fix that by simply moving the
string and matching a move inside that function too.

Coverity-Id: 480249
Coverity-Id: 480253
Change-Id: I5d9edea3174080822e82fffdd5f1548e8715e510
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Thiago Macieira 2025-04-07 08:27:11 -07:00
parent 52e2a89c63
commit 3f054d9220

View File

@ -1105,7 +1105,7 @@ template <typename String> void QUrlPrivate::setUserInfo(String value, QUrl::Par
qsizetype delimIndex = value.indexOf(u':');
if (delimIndex < 0) {
// no password
setUserName(value, mode);
setUserName(std::move(value), mode);
password.clear();
sectionIsPresent &= ~Password;
} else {
@ -2060,7 +2060,7 @@ void QUrl::setUserInfo(const QString &userInfo, ParsingMode mode)
return;
}
d->setUserInfo(trimmed, mode);
d->setUserInfo(std::move(trimmed), mode);
if (userInfo.isNull()) {
// QUrlPrivate::setUserInfo cleared almost everything
// but it leaves the UserName bit set