Reduce function call overhead

The arg() function of the QString class has a variable length argument
which allows to reduce the number of chained calls to the same function.
With proper formatting, readability is not affected.
This commit is contained in:
Gianluca Recchia 2018-10-28 12:23:06 +01:00
parent 18fd20f898
commit a67a574b89
No known key found for this signature in database
GPG Key ID: 3C2B4128D9A1F218
8 changed files with 30 additions and 40 deletions

View File

@ -362,7 +362,7 @@ void BrowserService::updateEntry(const QString& id,
if (!browserSettings()->alwaysAllowUpdate()) { if (!browserSettings()->alwaysAllowUpdate()) {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setWindowTitle(tr("KeePassXC: Update Entry")); msgBox.setWindowTitle(tr("KeePassXC: Update Entry"));
msgBox.setText(tr("Do you want to update the information in %1 - %2?").arg(QUrl(url).host()).arg(username)); msgBox.setText(tr("Do you want to update the information in %1 - %2?").arg(QUrl(url).host(), username));
msgBox.setStandardButtons(QMessageBox::Yes); msgBox.setStandardButtons(QMessageBox::Yes);
msgBox.addButton(QMessageBox::No); msgBox.addButton(QMessageBox::No);
msgBox.setDefaultButton(QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No);

View File

@ -77,7 +77,7 @@ int Extract::execute(const QStringList& arguments)
auto fileKey = QSharedPointer<FileKey>::create(); auto fileKey = QSharedPointer<FileKey>::create();
QString errorMsg; QString errorMsg;
if (!fileKey->load(keyFilePath, &errorMsg)) { if (!fileKey->load(keyFilePath, &errorMsg)) {
err << QObject::tr("Failed to load key file %1: %2").arg(keyFilePath).arg(errorMsg) << endl; err << QObject::tr("Failed to load key file %1: %2").arg(keyFilePath, errorMsg) << endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -811,7 +811,7 @@ void Group::removeEntry(Entry* entry)
{ {
Q_ASSERT_X(m_entries.contains(entry), Q_ASSERT_X(m_entries.contains(entry),
Q_FUNC_INFO, Q_FUNC_INFO,
QString("Group %1 does not contain %2").arg(this->name()).arg(entry->title()).toLatin1()); QString("Group %1 does not contain %2").arg(this->name(), entry->title()).toLatin1());
emit entryAboutToRemove(entry); emit entryAboutToRemove(entry);

View File

@ -95,7 +95,7 @@ Merger::ChangeList Merger::mergeGroup(const MergeContext& context)
// Entry is already present in the database. Update it. // Entry is already present in the database. Update it.
const bool locationChanged = targetEntry->timeInfo().locationChanged() < sourceEntry->timeInfo().locationChanged(); const bool locationChanged = targetEntry->timeInfo().locationChanged() < sourceEntry->timeInfo().locationChanged();
if (locationChanged && targetEntry->group() != context.m_targetGroup) { if (locationChanged && targetEntry->group() != context.m_targetGroup) {
changes << tr("Relocating %1 [%2]").arg(sourceEntry->title()).arg(sourceEntry->uuidToHex()); changes << tr("Relocating %1 [%2]").arg(sourceEntry->title(), sourceEntry->uuidToHex());
moveEntry(targetEntry, context.m_targetGroup); moveEntry(targetEntry, context.m_targetGroup);
} }
changes << resolveEntryConflict(context, sourceEntry, targetEntry); changes << resolveEntryConflict(context, sourceEntry, targetEntry);
@ -107,7 +107,7 @@ Merger::ChangeList Merger::mergeGroup(const MergeContext& context)
for (Group* sourceChildGroup : sourceChildGroups) { for (Group* sourceChildGroup : sourceChildGroups) {
Group* targetChildGroup = context.m_targetRootGroup->findGroupByUuid(sourceChildGroup->uuid()); Group* targetChildGroup = context.m_targetRootGroup->findGroupByUuid(sourceChildGroup->uuid());
if (!targetChildGroup) { if (!targetChildGroup) {
changes << tr("Creating missing %1 [%2]").arg(sourceChildGroup->name()).arg(sourceChildGroup->uuidToHex()); changes << tr("Creating missing %1 [%2]").arg(sourceChildGroup->name(), sourceChildGroup->uuidToHex());
targetChildGroup = sourceChildGroup->clone(Entry::CloneNoFlags, Group::CloneNoFlags); targetChildGroup = sourceChildGroup->clone(Entry::CloneNoFlags, Group::CloneNoFlags);
moveGroup(targetChildGroup, context.m_targetGroup); moveGroup(targetChildGroup, context.m_targetGroup);
TimeInfo timeinfo = targetChildGroup->timeInfo(); TimeInfo timeinfo = targetChildGroup->timeInfo();
@ -117,7 +117,7 @@ Merger::ChangeList Merger::mergeGroup(const MergeContext& context)
bool locationChanged = bool locationChanged =
targetChildGroup->timeInfo().locationChanged() < sourceChildGroup->timeInfo().locationChanged(); targetChildGroup->timeInfo().locationChanged() < sourceChildGroup->timeInfo().locationChanged();
if (locationChanged && targetChildGroup->parent() != context.m_targetGroup) { if (locationChanged && targetChildGroup->parent() != context.m_targetGroup) {
changes << tr("Relocating %1 [%2]").arg(sourceChildGroup->name()).arg(sourceChildGroup->uuidToHex()); changes << tr("Relocating %1 [%2]").arg(sourceChildGroup->name(), sourceChildGroup->uuidToHex());
moveGroup(targetChildGroup, context.m_targetGroup); moveGroup(targetChildGroup, context.m_targetGroup);
TimeInfo timeinfo = targetChildGroup->timeInfo(); TimeInfo timeinfo = targetChildGroup->timeInfo();
timeinfo.setLocationChanged(sourceChildGroup->timeInfo().locationChanged()); timeinfo.setLocationChanged(sourceChildGroup->timeInfo().locationChanged());
@ -146,7 +146,7 @@ Merger::ChangeList Merger::resolveGroupConflict(const MergeContext& context, con
// only if the other group is newer, update the existing one. // only if the other group is newer, update the existing one.
if (timeExisting < timeOther) { if (timeExisting < timeOther) {
changes << tr("Overwriting %1 [%2]").arg(sourceChildGroup->name()).arg(sourceChildGroup->uuidToHex()); changes << tr("Overwriting %1 [%2]").arg(sourceChildGroup->name(), sourceChildGroup->uuidToHex());
targetChildGroup->setName(sourceChildGroup->name()); targetChildGroup->setName(sourceChildGroup->name());
targetChildGroup->setNotes(sourceChildGroup->notes()); targetChildGroup->setNotes(sourceChildGroup->notes());
if (sourceChildGroup->iconNumber() == 0) { if (sourceChildGroup->iconNumber() == 0) {
@ -270,16 +270,12 @@ Merger::ChangeList Merger::resolveEntryConflict_Duplicate(const MergeContext& co
Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory); Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
moveEntry(clonedEntry, context.m_targetGroup); moveEntry(clonedEntry, context.m_targetGroup);
markOlderEntry(targetEntry); markOlderEntry(targetEntry);
changes << tr("Adding backup for older target %1 [%2]") changes << tr("Adding backup for older target %1 [%2]").arg(targetEntry->title(), targetEntry->uuidToHex());
.arg(targetEntry->title())
.arg(targetEntry->uuidToHex());
} else if (comparison > 0) { } else if (comparison > 0) {
Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory); Entry* clonedEntry = sourceEntry->clone(Entry::CloneNewUuid | Entry::CloneIncludeHistory);
moveEntry(clonedEntry, context.m_targetGroup); moveEntry(clonedEntry, context.m_targetGroup);
markOlderEntry(clonedEntry); markOlderEntry(clonedEntry);
changes << tr("Adding backup for older source %1 [%2]") changes << tr("Adding backup for older source %1 [%2]").arg(sourceEntry->title(), sourceEntry->uuidToHex());
.arg(sourceEntry->title())
.arg(sourceEntry->uuidToHex());
} }
return changes; return changes;
} }
@ -297,8 +293,7 @@ Merger::ChangeList Merger::resolveEntryConflict_KeepLocal(const MergeContext& co
// this type of merge changes the database timestamp since reapplying the // this type of merge changes the database timestamp since reapplying the
// old entry is an active change of the database! // old entry is an active change of the database!
changes << tr("Reapplying older target entry on top of newer source %1 [%2]") changes << tr("Reapplying older target entry on top of newer source %1 [%2]")
.arg(targetEntry->title()) .arg(targetEntry->title(), targetEntry->uuidToHex());
.arg(targetEntry->uuidToHex());
Entry* agedTargetEntry = targetEntry->clone(Entry::CloneNoFlags); Entry* agedTargetEntry = targetEntry->clone(Entry::CloneNoFlags);
targetEntry->addHistoryItem(agedTargetEntry); targetEntry->addHistoryItem(agedTargetEntry);
} }
@ -318,8 +313,7 @@ Merger::ChangeList Merger::resolveEntryConflict_KeepRemote(const MergeContext& c
// this type of merge changes the database timestamp since reapplying the // this type of merge changes the database timestamp since reapplying the
// old entry is an active change of the database! // old entry is an active change of the database!
changes << tr("Reapplying older source entry on top of newer target %1 [%2]") changes << tr("Reapplying older source entry on top of newer target %1 [%2]")
.arg(targetEntry->title()) .arg(targetEntry->title(), targetEntry->uuidToHex());
.arg(targetEntry->uuidToHex());
targetEntry->beginUpdate(); targetEntry->beginUpdate();
targetEntry->copyDataFrom(sourceEntry); targetEntry->copyDataFrom(sourceEntry);
targetEntry->endUpdate(); targetEntry->endUpdate();
@ -342,9 +336,7 @@ Merger::ChangeList Merger::resolveEntryConflict_MergeHistories(const MergeContex
qPrintable(targetEntry->title()), qPrintable(targetEntry->title()),
qPrintable(sourceEntry->title()), qPrintable(sourceEntry->title()),
qPrintable(currentGroup->name())); qPrintable(currentGroup->name()));
changes << tr("Synchronizing from newer source %1 [%2]") changes << tr("Synchronizing from newer source %1 [%2]").arg(targetEntry->title(), targetEntry->uuidToHex());
.arg(targetEntry->title())
.arg(targetEntry->uuidToHex());
moveEntry(clonedEntry, currentGroup); moveEntry(clonedEntry, currentGroup);
mergeHistory(targetEntry, clonedEntry, mergeMethod); mergeHistory(targetEntry, clonedEntry, mergeMethod);
eraseEntry(targetEntry); eraseEntry(targetEntry);
@ -355,9 +347,7 @@ Merger::ChangeList Merger::resolveEntryConflict_MergeHistories(const MergeContex
qPrintable(targetEntry->group()->name())); qPrintable(targetEntry->group()->name()));
const bool changed = mergeHistory(sourceEntry, targetEntry, mergeMethod); const bool changed = mergeHistory(sourceEntry, targetEntry, mergeMethod);
if (changed) { if (changed) {
changes << tr("Synchronizing from older source %1 [%2]") changes << tr("Synchronizing from older source %1 [%2]").arg(targetEntry->title(), targetEntry->uuidToHex());
.arg(targetEntry->title())
.arg(targetEntry->uuidToHex());
} }
} }
return changes; return changes;
@ -550,9 +540,9 @@ Merger::ChangeList Merger::mergeDeletions(const MergeContext& context)
} }
deletions << object; deletions << object;
if (entry->group()) { if (entry->group()) {
changes << tr("Deleting child %1 [%2]").arg(entry->title()).arg(entry->uuidToHex()); changes << tr("Deleting child %1 [%2]").arg(entry->title(), entry->uuidToHex());
} else { } else {
changes << tr("Deleting orphan %1 [%2]").arg(entry->title()).arg(entry->uuidToHex()); changes << tr("Deleting orphan %1 [%2]").arg(entry->title(), entry->uuidToHex());
} }
// Entry is inserted into deletedObjects after deletions are processed // Entry is inserted into deletedObjects after deletions are processed
eraseEntry(entry); eraseEntry(entry);
@ -576,9 +566,9 @@ Merger::ChangeList Merger::mergeDeletions(const MergeContext& context)
} }
deletions << object; deletions << object;
if (group->parentGroup()) { if (group->parentGroup()) {
changes << tr("Deleting child %1 [%2]").arg(group->name()).arg(group->uuidToHex()); changes << tr("Deleting child %1 [%2]").arg(group->name(), group->uuidToHex());
} else { } else {
changes << tr("Deleting orphan %1 [%2]").arg(group->name()).arg(group->uuidToHex()); changes << tr("Deleting orphan %1 [%2]").arg(group->name(), group->uuidToHex());
} }
eraseGroup(group); eraseGroup(group);
} }

View File

@ -65,9 +65,9 @@ AboutDialog::AboutDialog(QWidget* parent)
#endif #endif
debugInfo.append("\n").append(QString("%1\n- Qt %2\n- %3\n\n") debugInfo.append("\n").append(QString("%1\n- Qt %2\n- %3\n\n")
.arg(tr("Libraries:")) .arg(tr("Libraries:"),
.arg(QString::fromLocal8Bit(qVersion())) QString::fromLocal8Bit(qVersion()),
.arg(Crypto::backendVersion())); Crypto::backendVersion()));
#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
debugInfo.append(tr("Operating system: %1\nCPU architecture: %2\nKernel: %3 %4") debugInfo.append(tr("Operating system: %1\nCPU architecture: %2\nKernel: %3 %4")

View File

@ -309,10 +309,10 @@ void KMessageWidget::setMessageType(KMessageWidget::MessageType type)
"}" "}"
".QLabel { color: %6; }" ".QLabel { color: %6; }"
)) ))
.arg(bg0.name()) .arg(bg0.name(),
.arg(bg1.name()) bg1.name(),
.arg(bg2.name()) bg2.name(),
.arg(border.name()) border.name())
// DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px, // DefaultFrameWidth returns the size of the external margin + border width. We know our border is 1px,
// so we subtract this from the frame normal QStyle FrameWidth to get our margin // so we subtract this from the frame normal QStyle FrameWidth to get our margin
.arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this) - 1) .arg(style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, this) - 1)

View File

@ -36,9 +36,9 @@ void CsvParserModel::setFilename(const QString& filename)
QString CsvParserModel::getFileInfo() QString CsvParserModel::getFileInfo()
{ {
QString a(tr("%1, %2, %3", "file info: bytes, rows, columns") QString a(tr("%1, %2, %3", "file info: bytes, rows, columns")
.arg(tr("%n byte(s)", nullptr, getFileSize())) .arg(tr("%n byte(s)", nullptr, getFileSize()),
.arg(tr("%n row(s)", nullptr, getCsvRows())) tr("%n row(s)", nullptr, getCsvRows()),
.arg(tr("%n column(s)", nullptr, qMax(0, getCsvCols() - 1)))); tr("%n column(s)", nullptr, qMax(0, getCsvCols() - 1))));
return a; return a;
} }

View File

@ -106,9 +106,9 @@ QString Totp::writeSettings(const QSharedPointer<Totp::Settings> settings, const
// OTP Url output // OTP Url output
if (settings->otpUrl || forceOtp) { if (settings->otpUrl || forceOtp) {
auto urlstring = QString("otpauth://totp/%1:%2?secret=%3&period=%4&digits=%5&issuer=%1") auto urlstring = QString("otpauth://totp/%1:%2?secret=%3&period=%4&digits=%5&issuer=%1")
.arg(title.isEmpty() ? "KeePassXC" : QString(QUrl::toPercentEncoding(title))) .arg(title.isEmpty() ? "KeePassXC" : QString(QUrl::toPercentEncoding(title)),
.arg(username.isEmpty() ? "none" : QString(QUrl::toPercentEncoding(username))) username.isEmpty() ? "none" : QString(QUrl::toPercentEncoding(username)),
.arg(QString(Base32::sanitizeInput(settings->key.toLatin1()))) QString(Base32::sanitizeInput(settings->key.toLatin1())))
.arg(settings->step) .arg(settings->step)
.arg(settings->digits); .arg(settings->digits);