qt, build: Optimize string concatenation

The defined QT_USE_QSTRINGBUILDER macro means using the QStringBuilder
for efficient string concatenation in all Qt code by default.
pull/22078/head
Hennadii Stepanov 4 years ago
parent b8593616dc
commit 3fd3a0fc87
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

@ -288,7 +288,7 @@ RES_ANIMATION = $(wildcard $(srcdir)/qt/res/animation/spinner-*.png)
BITCOIN_RC = qt/res/bitcoin-qt-res.rc BITCOIN_RC = qt/res/bitcoin-qt-res.rc
BITCOIN_QT_INCLUDES = -DQT_NO_KEYWORDS BITCOIN_QT_INCLUDES = -DQT_NO_KEYWORDS -DQT_USE_QSTRINGBUILDER
qt_libbitcoinqt_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \ qt_libbitcoinqt_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
$(QT_INCLUDES) $(QT_DBUS_INCLUDES) $(QR_CFLAGS) $(QT_INCLUDES) $(QT_DBUS_INCLUDES) $(QR_CFLAGS)

@ -21,6 +21,7 @@
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS #include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
#include <QDebug> #include <QDebug>
#include <QLatin1Char>
#include <QSettings> #include <QSettings>
#include <QStringList> #include <QStringList>
@ -244,7 +245,7 @@ static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port) static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port)
{ {
settings.setValue(name, ip_port.ip + ":" + ip_port.port); settings.setValue(name, QString{ip_port.ip + QLatin1Char(':') + ip_port.port});
} }
static const QString GetDefaultProxyAddress() static const QString GetDefaultProxyAddress()

@ -114,7 +114,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
return (qint64)rec->nodeStats.nodeid; return (qint64)rec->nodeStats.nodeid;
case Address: case Address:
// prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection // prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection
return QString(rec->nodeStats.fInbound ? "" : "") + QString::fromStdString(rec->nodeStats.addrName); return QString::fromStdString((rec->nodeStats.fInbound ? "" : "") + rec->nodeStats.addrName);
case ConnectionType: case ConnectionType:
return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false); return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false);
case Network: case Network:

@ -14,6 +14,9 @@
#include <utility> #include <utility>
#include <QLatin1Char>
#include <QLatin1String>
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) : RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
QAbstractTableModel(parent), walletModel(parent) QAbstractTableModel(parent), walletModel(parent)
{ {
@ -124,7 +127,11 @@ void RecentRequestsTableModel::updateAmountColumnTitle()
/** Gets title for amount column including current display unit if optionsModel reference available. */ /** Gets title for amount column including current display unit if optionsModel reference available. */
QString RecentRequestsTableModel::getAmountTitle() QString RecentRequestsTableModel::getAmountTitle()
{ {
return (this->walletModel->getOptionsModel() != nullptr) ? tr("Requested") + " ("+BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")" : ""; if (!walletModel->getOptionsModel()) return {};
return tr("Requested") +
QLatin1String(" (") +
BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) +
QLatin1Char(')');
} }
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const

@ -236,7 +236,7 @@ void TestGUI(interfaces::Node& node)
QCOMPARE(uri.count("amount=0.00000001"), 2); QCOMPARE(uri.count("amount=0.00000001"), 2);
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:")); QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString("0.00000001 ") + QString::fromStdString(CURRENCY_UNIT)); QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString::fromStdString("0.00000001 " + CURRENCY_UNIT));
QCOMPARE(uri.count("label=TEST_LABEL_1"), 2); QCOMPARE(uri.count("label=TEST_LABEL_1"), 2);
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_tag")->text(), QString("Label:")); QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_tag")->text(), QString("Label:"));

@ -26,6 +26,8 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <QLatin1String>
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks) QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
{ {
if (!status.is_final) if (!status.is_final)
@ -38,16 +40,18 @@ QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const i
else else
{ {
int nDepth = status.depth_in_main_chain; int nDepth = status.depth_in_main_chain;
if (nDepth < 0) if (nDepth < 0) {
return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth); return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
else if (nDepth == 0) } else if (nDepth == 0) {
return tr("0/unconfirmed, %1").arg((inMempool ? tr("in memory pool") : tr("not in memory pool"))) + (status.is_abandoned ? ", "+tr("abandoned") : ""); const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
else if (nDepth < 6) return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
} else if (nDepth < 6) {
return tr("%1/unconfirmed").arg(nDepth); return tr("%1/unconfirmed").arg(nDepth);
else } else {
return tr("%1 confirmations").arg(nDepth); return tr("%1 confirmations").arg(nDepth);
} }
} }
}
// Takes an encoded PaymentRequest as a string and tries to find the Common Name of the X.509 certificate // Takes an encoded PaymentRequest as a string and tries to find the Common Name of the X.509 certificate
// used to sign the PaymentRequest. // used to sign the PaymentRequest.

@ -25,6 +25,8 @@
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QIcon> #include <QIcon>
#include <QLatin1Char>
#include <QLatin1String>
#include <QList> #include <QList>
@ -409,9 +411,9 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
{ {
QString watchAddress; QString watchAddress;
if (tooltip) { if (tooltip && wtx->involvesWatchAddress) {
// Mark transactions involving watch-only addresses by adding " (watch-only)" // Mark transactions involving watch-only addresses by adding " (watch-only)"
watchAddress = wtx->involvesWatchAddress ? QString(" (") + tr("watch-only") + QString(")") : ""; watchAddress = QLatin1String(" (") + tr("watch-only") + QLatin1Char(')');
} }
switch(wtx->type) switch(wtx->type)

Loading…
Cancel
Save