Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace QString() with QStringLiteral() for better performance #7422

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ int main(int argc, char **argv)

#ifdef Q_OS_WIN
// Ensure OpenSSL config file is only loaded from app directory
QString opensslConf = QCoreApplication::applicationDirPath() + QString("/openssl.cnf");
QString opensslConf = QCoreApplication::applicationDirPath() + QStringLiteral("/openssl.cnf");
qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit());
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Application::Application(int &argc, char **argv)

#ifdef Q_OS_WIN
// Ensure OpenSSL config file is only loaded from app directory
QString opensslConf = QCoreApplication::applicationDirPath() + QString("/openssl.cnf");
QString opensslConf = QCoreApplication::applicationDirPath() + QStringLiteral("/openssl.cnf");
qputenv("OPENSSL_CONF", opensslConf.toLocal8Bit());

// Set up event listener for Windows theme changing
Expand Down
4 changes: 2 additions & 2 deletions src/gui/cloudproviders/cloudproviderwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CloudProviderWrapper::CloudProviderWrapper(QObject *parent, Folder *folder, int
{
GMenuModel *model = nullptr;
GActionGroup *action_group = nullptr;
QString accountName = QString("Folder/%1").arg(folderId);
QString accountName = QStringLiteral("Folder/%1").arg(folderId);

_cloudProvider = CLOUD_PROVIDERS_PROVIDER_EXPORTER(cloudprovider);
_cloudProviderAccount = cloud_providers_account_exporter_new(_cloudProvider, accountName.toUtf8().data());
Expand Down Expand Up @@ -170,7 +170,7 @@ void CloudProviderWrapper::slotUpdateProgress(const QString &folder, const Progr

void CloudProviderWrapper::updateStatusText(QString statusText)
{
QString status = QString("%1 - %2").arg(_folder->accountState()->stateString(_folder->accountState()->state()), statusText);
QString status = QStringLiteral("%1 - %2").arg(_folder->accountState()->stateString(_folder->accountState()->state()), statusText);
cloud_providers_account_exporter_set_status_details(_cloudProviderAccount, status.toUtf8().data());
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/creds/flow2auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void Flow2Auth::slotPollTimerTimeout()
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

auto requestBody = new QBuffer;
QUrlQuery arguments(QString("token=%1").arg(_pollToken));
QUrlQuery arguments(QStringLiteral("token=%1").arg(_pollToken));
requestBody->setData(arguments.query(QUrl::FullyEncoded).toLatin1());

auto job = _account->sendRequest("POST", _pollEndpoint, req, requestBody);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ QString ShareModel::avatarUrlForShare(const SharePtr &share) const
const auto provider = QStringLiteral("image://tray-image-provider/");
const auto userId = share->getShareWith()->shareWith();
const auto avatarUrl = Utility::concatUrlPath(_accountState->account()->url(),
QString("remote.php/dav/avatars/%1/%2.png").arg(userId, QString::number(64))).toString();
QStringLiteral("remote.php/dav/avatars/%1/%2.png").arg(userId, QString::number(64))).toString();
return QString(provider + avatarUrl);
}

Expand Down Expand Up @@ -1403,7 +1403,7 @@ QString ShareModel::generatePassword()
static const QRegularExpression lowercaseMatch("[a-z]");
static const QRegularExpression uppercaseMatch("[A-Z]");
static const QRegularExpression numberMatch("[0-9]");
static const QRegularExpression specialCharMatch(QString("[%1]").arg(specialChars.data()));
static const QRegularExpression specialCharMatch(QStringLiteral("[%1]").arg(specialChars.data()));

static const std::map<std::string_view, QRegularExpression> matchMap{
{lowercaseAlphabet, lowercaseMatch},
Expand Down
2 changes: 1 addition & 1 deletion src/gui/foldercreationdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FolderCreationDialog::FolderCreationDialog(const QString &destination, QWidget *
ui->newFolderNameEdit->setText(suggestedFolderNamePrefix);
} else {
for (unsigned int i = 2; i < std::numeric_limits<unsigned int>::max(); ++i) {
const QString suggestedPostfix = QString(" (%1)").arg(i);
const QString suggestedPostfix = QStringLiteral(" (%1)").arg(i);

if (!QDir(newFolderFullPath + suggestedPostfix).exists()) {
ui->newFolderNameEdit->setText(suggestedFolderNamePrefix + suggestedPostfix);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
if (folderInfo->_hasError) {
return {tr("Error while loading the list of folders from the server.")
+ QString("\n")
+ QStringLiteral("\n")
+ folderInfo->_lastErrorString};
} else {
return tr("Fetching folder list from server …");
Expand Down
2 changes: 1 addition & 1 deletion src/gui/ocssharejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void OcsShareJob::getShares(const QString &path, const QMap<QString, QString> &p
setVerb("GET");

addParam(QString::fromLatin1("path"), path);
addParam(QString::fromLatin1("reshares"), QString("true"));
addParam(QString::fromLatin1("reshares"), QStringLiteral("true"));

for (auto it = std::cbegin(params); it != std::cend(params); ++it) {
addParam(it.key(), it.value());
Expand Down
20 changes: 10 additions & 10 deletions src/gui/remotewipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void RemoteWipe::startCheckJobWithAppPassword(QString pwd){
request.setUrl(requestUrl);
request.setSslConfiguration(_account->getOrCreateSslConfig());
auto requestBody = new QBuffer;
QUrlQuery arguments(QString("token=%1").arg(_appPassword));
QUrlQuery arguments(QStringLiteral("token=%1").arg(_appPassword));
requestBody->setData(arguments.query(QUrl::FullyEncoded).toLatin1());
_networkReplyCheck = _networkManager.post(request, requestBody);
QObject::connect(&_networkManager, &QNetworkAccessManager::sslErrors,
Expand All @@ -79,16 +79,16 @@ void RemoteWipe::checkJobSlot()
jsonParseError.error != QJsonParseError::NoError) {
QString errorFromJson = json["error"].toString();
if (!errorFromJson.isEmpty()) {
qCWarning(lcRemoteWipe) << QString("Error returned from the server: <em>%1<em>")
qCWarning(lcRemoteWipe) << QStringLiteral("Error returned from the server: <em>%1<em>")
.arg(errorFromJson.toHtmlEscaped());
} else if (_networkReplyCheck->error() != QNetworkReply::NoError) {
qCWarning(lcRemoteWipe) << QString("There was an error accessing the 'token' endpoint: <br><em>%1</em>")
qCWarning(lcRemoteWipe) << QStringLiteral("There was an error accessing the 'token' endpoint: <br><em>%1</em>")
.arg(_networkReplyCheck->errorString().toHtmlEscaped());
} else if (jsonParseError.error != QJsonParseError::NoError) {
qCWarning(lcRemoteWipe) << QString("Could not parse the JSON returned from the server: <br><em>%1</em>")
qCWarning(lcRemoteWipe) << QStringLiteral("Could not parse the JSON returned from the server: <br><em>%1</em>")
.arg(jsonParseError.errorString());
} else {
qCWarning(lcRemoteWipe) << QString("The reply from the server did not contain all expected fields");
qCWarning(lcRemoteWipe) << QStringLiteral("The reply from the server did not contain all expected fields");
}

// check for wipe request
Expand Down Expand Up @@ -136,7 +136,7 @@ void RemoteWipe::notifyServerSuccessJob(AccountState *accountState, bool dataWip
request.setUrl(requestUrl);
request.setSslConfiguration(_account->getOrCreateSslConfig());
auto requestBody = new QBuffer;
QUrlQuery arguments(QString("token=%1").arg(_appPassword));
QUrlQuery arguments(QStringLiteral("token=%1").arg(_appPassword));
requestBody->setData(arguments.query(QUrl::FullyEncoded).toLatin1());
_networkReplySuccess = _networkManager.post(request, requestBody);
QObject::connect(_networkReplySuccess, &QNetworkReply::finished, this,
Expand All @@ -153,16 +153,16 @@ void RemoteWipe::notifyServerSuccessJobSlot()
jsonParseError.error != QJsonParseError::NoError) {
QString errorFromJson = json["error"].toString();
if (!errorFromJson.isEmpty()) {
qCWarning(lcRemoteWipe) << QString("Error returned from the server: <em>%1</em>")
qCWarning(lcRemoteWipe) << QStringLiteral("Error returned from the server: <em>%1</em>")
.arg(errorFromJson.toHtmlEscaped());
} else if (_networkReplySuccess->error() != QNetworkReply::NoError) {
qCWarning(lcRemoteWipe) << QString("There was an error accessing the 'success' endpoint: <br><em>%1</em>")
qCWarning(lcRemoteWipe) << QStringLiteral("There was an error accessing the 'success' endpoint: <br><em>%1</em>")
.arg(_networkReplySuccess->errorString().toHtmlEscaped());
} else if (jsonParseError.error != QJsonParseError::NoError) {
qCWarning(lcRemoteWipe) << QString("Could not parse the JSON returned from the server: <br><em>%1</em>")
qCWarning(lcRemoteWipe) << QStringLiteral("Could not parse the JSON returned from the server: <br><em>%1</em>")
.arg(jsonParseError.errorString());
} else {
qCWarning(lcRemoteWipe) << QString("The reply from the server did not contain all expected fields.");
qCWarning(lcRemoteWipe) << QStringLiteral("The reply from the server did not contain all expected fields.");
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,13 +1167,13 @@ void SocketApi::command_GET_STRINGS(const QString &argument, SocketListener *lis
{ "EMAIL_PRIVATE_LINK_MENU_TITLE", tr("Send private link by email …") },
{ "CONTEXT_MENU_ICON", APPLICATION_ICON_NAME },
} };
listener->sendMessage(QString("GET_STRINGS:BEGIN"));
listener->sendMessage(QStringLiteral("GET_STRINGS:BEGIN"));
for (const auto& key_value : strings) {
if (argument.isEmpty() || argument == QLatin1String(key_value.first)) {
listener->sendMessage(QString("STRING:%1:%2").arg(key_value.first, key_value.second));
listener->sendMessage(QStringLiteral("STRING:%1:%2").arg(key_value.first, key_value.second));
}
}
listener->sendMessage(QString("GET_STRINGS:END"));
listener->sendMessage(QStringLiteral("GET_STRINGS:END"));
}

void SocketApi::sendSharingContextMenuOptions(const FileData &fileData, SocketListener *listener, SharingContextItemEncryptedFlag itemEncryptionFlag, SharingContextItemRootEncryptedFolderFlag rootE2eeFolderFlag)
Expand Down Expand Up @@ -1364,7 +1364,7 @@ SocketApi::FileData SocketApi::FileData::parentFolder() const

void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListener *listener)
{
listener->sendMessage(QString("GET_MENU_ITEMS:BEGIN"), true);
listener->sendMessage(QStringLiteral("GET_MENU_ITEMS:BEGIN"), true);
const QStringList files = split(argument);

// Find the common sync folder.
Expand Down Expand Up @@ -1522,7 +1522,7 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
}
}

listener->sendMessage(QString("GET_MENU_ITEMS:END"));
listener->sendMessage(QStringLiteral("GET_MENU_ITEMS:END"));
}

DirectEditor* SocketApi::getDirectEditorForLocalFile(const QString &localFile)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void SyncRunFileLog::start(const QString &folderPath)
if(QString::compare(folderPath,line,Qt::CaseSensitive)!=0) {
depthIndex++;
if(depthIndex <= length) {
filenameSingle = folderPath.split(QLatin1String("/")).at(length - depthIndex) + QString("_") ///
filenameSingle = folderPath.split(QLatin1String("/")).at(length - depthIndex) + QStringLiteral("_") ///
+ filenameSingle;
filename = logpath+ QLatin1String("/") + filenameSingle + QLatin1String("_sync.log");
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/tray/activitylistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
case AccountRole:
return a._accName;
case PointInTimeRole:
//return a._id == -1 ? "" : QString("%1 - %2").arg(Utility::timeAgoInWords(a._dateTime.toLocalTime()), a._dateTime.toLocalTime().toString(Qt::DefaultLocaleShortDate));
//return a._id == -1 ? "" : QStringLiteral("%1 - %2").arg(Utility::timeAgoInWords(a._dateTime.toLocalTime()), a._dateTime.toLocalTime().toString(Qt::DefaultLocaleShortDate));
return a._id == -1 ? "" : Utility::timeAgoInWords(a._dateTime.toLocalTime());
case AccountConnectedRole:
return (ast && ast->isConnected());
Expand Down
10 changes: 5 additions & 5 deletions src/gui/tray/unifiedsearchresultslistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void UnifiedSearchResultsListModel::slotSearchTermEditingFinished()
&UnifiedSearchResultsListModel::slotSearchTermEditingFinished);

if (!_accountState || !_accountState->account()) {
qCCritical(lcUnifiedSearch) << QString("Account state is invalid. Could not start search!");
qCCritical(lcUnifiedSearch) << QStringLiteral("Account state is invalid. Could not start search!");
return;
}

Expand All @@ -401,14 +401,14 @@ void UnifiedSearchResultsListModel::slotFetchProvidersFinished(const QJsonDocume
const auto job = qobject_cast<JsonApiJob *>(sender());

if (!job) {
qCCritical(lcUnifiedSearch) << QString("Failed to fetch providers.").arg(_searchTerm);
qCCritical(lcUnifiedSearch) << QStringLiteral("Failed to fetch providers.").arg(_searchTerm);
_errorString += tr("Failed to fetch providers.") + QLatin1Char('\n');
emit errorStringChanged();
return;
}

if (statusCode != 200) {
qCCritical(lcUnifiedSearch) << QString("%1: Failed to fetch search providers for '%2'. Error: %3")
qCCritical(lcUnifiedSearch) << QStringLiteral("%1: Failed to fetch search providers for '%2'. Error: %3")
.arg(statusCode)
.arg(_searchTerm)
.arg(job->errorString());
Expand Down Expand Up @@ -446,7 +446,7 @@ void UnifiedSearchResultsListModel::slotSearchForProviderFinished(const QJsonDoc
const auto job = qobject_cast<JsonApiJob *>(sender());

if (!job) {
qCCritical(lcUnifiedSearch) << QString("Search has failed for '%2'.").arg(_searchTerm);
qCCritical(lcUnifiedSearch) << QStringLiteral("Search has failed for '%2'.").arg(_searchTerm);
_errorString += tr("Search has failed for '%2'.").arg(_searchTerm) + QLatin1Char('\n');
emit errorStringChanged();
return;
Expand All @@ -471,7 +471,7 @@ void UnifiedSearchResultsListModel::slotSearchForProviderFinished(const QJsonDoc
}

if (statusCode != 200) {
qCCritical(lcUnifiedSearch) << QString("%1: Search has failed for '%2'. Error: %3")
qCCritical(lcUnifiedSearch) << QStringLiteral("%1: Search has failed for '%2'. Error: %3")
.arg(statusCode)
.arg(_searchTerm)
.arg(job->errorString());
Expand Down
2 changes: 1 addition & 1 deletion src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void OCUpdater::slotStartInstaller()
};

QString msiLogFile = cfg.configPath() + "msi.log";
QString command = QString("&{msiexec /i '%1' /L*V '%2'| Out-Null ; &'%3'}")
QString command = QStringLiteral("&{msiexec /i '%1' /L*V '%2'| Out-Null ; &'%3'}")
.arg(preparePathForPowershell(updateFile))
.arg(preparePathForPowershell(msiLogFile))
.arg(preparePathForPowershell(QCoreApplication::applicationFilePath()));
Expand Down
2 changes: 1 addition & 1 deletion src/gui/updater/updateinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ UpdateInfo UpdateInfo::parseString(const QString &xml, bool *ok)
if (!doc.setContent(xml, false, &errorMsg, &errorLine, &errorCol)) {
qCWarning(lcUpdater).noquote().nospace() << errorMsg << " at " << errorLine << "," << errorCol
<< "\n" << xml.split("\n").value(errorLine-1) << "\n"
<< QString(" ").repeated(errorCol - 1) << "^\n"
<< QStringLiteral(" ").repeated(errorCol - 1) << "^\n"
<< "->" << xml << "<-";
if (ok)
*ok = false;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/wizard/flow2authwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void Flow2AuthWidget::slotStatusChanged(Flow2Auth::PollStatus status, int second
_statusUpdateSkipCount--;
break;
}
_ui.statusLabel->setText(tr("Waiting for authorization") + QString("… (%1)").arg(secondsLeft));
_ui.statusLabel->setText(tr("Waiting for authorization") + QStringLiteral("… (%1)").arg(secondsLeft));
stopSpinner(true);
break;
case Flow2Auth::statusPollNow:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/wizard/welcomepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ void WelcomePage::styleSlideShow()
_ui->slideShow->addSlide(wizardTalkIconFileName, tr("Screensharing, online meetings & web conferences"));

const auto isDarkBackground = Theme::isDarkColor(backgroundColor);
_ui->slideShowNextButton->setIcon(theme->uiThemeIcon(QString("control-next.svg"), isDarkBackground));
_ui->slideShowPreviousButton->setIcon(theme->uiThemeIcon(QString("control-prev.svg"), isDarkBackground));
_ui->slideShowNextButton->setIcon(theme->uiThemeIcon(QStringLiteral("control-next.svg"), isDarkBackground));
_ui->slideShowPreviousButton->setIcon(theme->uiThemeIcon(QStringLiteral("control-prev.svg"), isDarkBackground));
}

void WelcomePage::setupSlideShow()
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/abstractnetworkjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void AbstractNetworkJob::start()
_timer.start();

const QUrl url = account()->url();
const QString displayUrl = QString("%1://%2%3").arg(url.scheme()).arg(url.host()).arg(url.path());
const QString displayUrl = QStringLiteral("%1://%2%3").arg(url.scheme()).arg(url.host()).arg(url.path());

QString parentMetaObjectName = parent() ? parent()->metaObject()->className() : "";
qCInfo(lcNetworkJob) << metaObject()->className() << "created for" << displayUrl << "+" << path() << parentMetaObjectName;
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void Account::setAvatar(const QImage &img)

QString Account::displayName() const
{
QString dn = QString("%1@%2").arg(credentials()->user(), _url.host());
QString dn = QStringLiteral("%1@%2").arg(credentials()->user(), _url.host());
int port = url().port();
if (port > 0 && port != 80 && port != 443) {
dn.append(QLatin1Char(':'));
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/clientproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const char *ClientProxy::proxyTypeToCStr(QNetworkProxy::ProxyType type)

QString ClientProxy::printQNetworkProxy(const QNetworkProxy &proxy)
{
return QString("%1://%2:%3").arg(proxyTypeToCStr(proxy.type())).arg(proxy.hostName()).arg(proxy.port());
return QStringLiteral("%1://%2:%3").arg(proxyTypeToCStr(proxy.type())).arg(proxy.hostName()).arg(proxy.port());
}

void ClientProxy::setupQtProxyFromConfig()
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ QString ConfigFile::backup(const QString &fileName) const
}

QString backupFile =
QString("%1.backup_%2%3")
QStringLiteral("%1.backup_%2%3")
.arg(baseFilePath)
.arg(QDateTime::currentDateTime().toString("yyyyMMdd_HHmmss"))
.arg(versionString);
Expand Down
Loading