Skip to content

Commit 3fd3a0f

Browse files
committed
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.
1 parent b859361 commit 3fd3a0f

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

src/Makefile.qt.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ RES_ANIMATION = $(wildcard $(srcdir)/qt/res/animation/spinner-*.png)
288288

289289
BITCOIN_RC = qt/res/bitcoin-qt-res.rc
290290

291-
BITCOIN_QT_INCLUDES = -DQT_NO_KEYWORDS
291+
BITCOIN_QT_INCLUDES = -DQT_NO_KEYWORDS -DQT_USE_QSTRINGBUILDER
292292

293293
qt_libbitcoinqt_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
294294
$(QT_INCLUDES) $(QT_DBUS_INCLUDES) $(QR_CFLAGS)

src/qt/optionsmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <validation.h> // For DEFAULT_SCRIPTCHECK_THREADS
2222

2323
#include <QDebug>
24+
#include <QLatin1Char>
2425
#include <QSettings>
2526
#include <QStringList>
2627

@@ -244,7 +245,7 @@ static ProxySetting GetProxySetting(QSettings &settings, const QString &name)
244245

245246
static void SetProxySetting(QSettings &settings, const QString &name, const ProxySetting &ip_port)
246247
{
247-
settings.setValue(name, ip_port.ip + ":" + ip_port.port);
248+
settings.setValue(name, QString{ip_port.ip + QLatin1Char(':') + ip_port.port});
248249
}
249250

250251
static const QString GetDefaultProxyAddress()

src/qt/peertablemodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
114114
return (qint64)rec->nodeStats.nodeid;
115115
case Address:
116116
// prepend to peer address down-arrow symbol for inbound connection and up-arrow for outbound connection
117-
return QString(rec->nodeStats.fInbound ? "" : "") + QString::fromStdString(rec->nodeStats.addrName);
117+
return QString::fromStdString((rec->nodeStats.fInbound ? "" : "") + rec->nodeStats.addrName);
118118
case ConnectionType:
119119
return GUIUtil::ConnectionTypeToQString(rec->nodeStats.m_conn_type, /* prepend_direction */ false);
120120
case Network:

src/qt/recentrequeststablemodel.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#include <utility>
1616

17+
#include <QLatin1Char>
18+
#include <QLatin1String>
19+
1720
RecentRequestsTableModel::RecentRequestsTableModel(WalletModel *parent) :
1821
QAbstractTableModel(parent), walletModel(parent)
1922
{
@@ -124,7 +127,11 @@ void RecentRequestsTableModel::updateAmountColumnTitle()
124127
/** Gets title for amount column including current display unit if optionsModel reference available. */
125128
QString RecentRequestsTableModel::getAmountTitle()
126129
{
127-
return (this->walletModel->getOptionsModel() != nullptr) ? tr("Requested") + " ("+BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) + ")" : "";
130+
if (!walletModel->getOptionsModel()) return {};
131+
return tr("Requested") +
132+
QLatin1String(" (") +
133+
BitcoinUnits::shortName(this->walletModel->getOptionsModel()->getDisplayUnit()) +
134+
QLatin1Char(')');
128135
}
129136

130137
QModelIndex RecentRequestsTableModel::index(int row, int column, const QModelIndex &parent) const

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void TestGUI(interfaces::Node& node)
236236

237237
QCOMPARE(uri.count("amount=0.00000001"), 2);
238238
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_tag")->text(), QString("Amount:"));
239-
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString("0.00000001 ") + QString::fromStdString(CURRENCY_UNIT));
239+
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("amount_content")->text(), QString::fromStdString("0.00000001 " + CURRENCY_UNIT));
240240

241241
QCOMPARE(uri.count("label=TEST_LABEL_1"), 2);
242242
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("label_tag")->text(), QString("Label:"));

src/qt/transactiondesc.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <stdint.h>
2727
#include <string>
2828

29+
#include <QLatin1String>
30+
2931
QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const interfaces::WalletTxStatus& status, bool inMempool, int numBlocks)
3032
{
3133
if (!status.is_final)
@@ -38,14 +40,16 @@ QString TransactionDesc::FormatTxStatus(const interfaces::WalletTx& wtx, const i
3840
else
3941
{
4042
int nDepth = status.depth_in_main_chain;
41-
if (nDepth < 0)
43+
if (nDepth < 0) {
4244
return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
43-
else if (nDepth == 0)
44-
return tr("0/unconfirmed, %1").arg((inMempool ? tr("in memory pool") : tr("not in memory pool"))) + (status.is_abandoned ? ", "+tr("abandoned") : "");
45-
else if (nDepth < 6)
45+
} else if (nDepth == 0) {
46+
const QString abandoned{status.is_abandoned ? QLatin1String(", ") + tr("abandoned") : QString()};
47+
return tr("0/unconfirmed, %1").arg(inMempool ? tr("in memory pool") : tr("not in memory pool")) + abandoned;
48+
} else if (nDepth < 6) {
4649
return tr("%1/unconfirmed").arg(nDepth);
47-
else
50+
} else {
4851
return tr("%1 confirmations").arg(nDepth);
52+
}
4953
}
5054
}
5155

src/qt/transactiontablemodel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <QDateTime>
2626
#include <QDebug>
2727
#include <QIcon>
28+
#include <QLatin1Char>
29+
#include <QLatin1String>
2830
#include <QList>
2931

3032

@@ -409,9 +411,9 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx
409411
QString TransactionTableModel::formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
410412
{
411413
QString watchAddress;
412-
if (tooltip) {
414+
if (tooltip && wtx->involvesWatchAddress) {
413415
// Mark transactions involving watch-only addresses by adding " (watch-only)"
414-
watchAddress = wtx->involvesWatchAddress ? QString(" (") + tr("watch-only") + QString(")") : "";
416+
watchAddress = QLatin1String(" (") + tr("watch-only") + QLatin1Char(')');
415417
}
416418

417419
switch(wtx->type)

0 commit comments

Comments
 (0)