From 6aa935cd92deb035739e8fea329ca2c4a435de54 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 18 Aug 2016 11:57:26 +0300 Subject: Use QString::fromLatin1() less to avoid string allocations QString::fromLatin1 always allocates memory, but there are cases where we can avoid/reduce allocations or/and reduce text size, e.g.: QStringBuilder expressions Fix: replace QString::fromLatin1 with QL1S QString::fromLatin1().arg(String) pattern Fix: replace with QStringBuilder Overloaded functions with QL1S arg Fix: replace QString::fromLatin1 with QL1S In rare cases if there is no overloaded function with QL1S and we have deal with string literal, replace QString::fromLatin1 with QStringLiteral. Change-Id: Iabe1a3cc0830f40ef78a0548afa4368583c31def Reviewed-by: Edward Welbourne --- src/widgets/widgets/qlcdnumber.cpp | 4 ++-- src/widgets/widgets/qpushbutton.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/widgets/widgets') diff --git a/src/widgets/widgets/qlcdnumber.cpp b/src/widgets/widgets/qlcdnumber.cpp index 2703e5d8a3..aa052ef5cb 100644 --- a/src/widgets/widgets/qlcdnumber.cpp +++ b/src/widgets/widgets/qlcdnumber.cpp @@ -188,8 +188,8 @@ static QString int2string(int num, int base, int ndigits, bool *oflow) } while (n != 0); len = ndigits - len; if (len > 0) - s.fill(QLatin1Char(' '), len); - s += QString::fromLatin1(p); + s += QString(len, QLatin1Char(' ')); + s += QLatin1String(p); } break; } diff --git a/src/widgets/widgets/qpushbutton.cpp b/src/widgets/widgets/qpushbutton.cpp index 5608a4aff9..bf10b9fb75 100644 --- a/src/widgets/widgets/qpushbutton.cpp +++ b/src/widgets/widgets/qpushbutton.cpp @@ -415,7 +415,7 @@ QSize QPushButton::sizeHint() const QString s(text()); bool empty = s.isEmpty(); if (empty) - s = QString::fromLatin1("XXXX"); + s = QStringLiteral("XXXX"); QFontMetrics fm = fontMetrics(); QSize sz = fm.size(Qt::TextShowMnemonic, s); if(!empty || !w) -- cgit v1.2.3