From 6b2071c697d4c48f0cd289b28b443ebffc3432e6 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 22 Aug 2016 15:32:03 +0300 Subject: Use QStringBuilder more to optimize memory allocations Change-Id: I2939ffa10496fdc59e0402a9cb54458565ccd657 Reviewed-by: Thiago Macieira --- src/corelib/global/qlibraryinfo.cpp | 8 ++++---- src/gui/text/qfontdatabase.cpp | 7 ++----- src/gui/text/qplatformfontdatabase.cpp | 6 ++---- src/platformsupport/themes/qabstractfileiconengine.cpp | 3 +-- src/plugins/platforms/xcb/qxcbmime.cpp | 4 +--- src/plugins/platforms/xcb/qxcbscreen.cpp | 3 +-- src/tools/rcc/rcc.cpp | 4 +--- 7 files changed, 12 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/corelib/global/qlibraryinfo.cpp b/src/corelib/global/qlibraryinfo.cpp index 4303f74709..1a7d64780f 100644 --- a/src/corelib/global/qlibraryinfo.cpp +++ b/src/corelib/global/qlibraryinfo.cpp @@ -616,10 +616,10 @@ QStringList QLibraryInfo::platformPluginArguments(const QString &platformName) #if !defined(QT_BUILD_QMAKE) && !defined(QT_NO_SETTINGS) QScopedPointer settings(QLibraryInfoPrivate::findConfiguration()); if (!settings.isNull()) { - QString key = QLatin1String(platformsSection); - key += QLatin1Char('/'); - key += platformName; - key += QLatin1String("Arguments"); + const QString key = QLatin1String(platformsSection) + + QLatin1Char('/') + + platformName + + QLatin1String("Arguments"); return settings->value(key).toStringList(); } #endif // !QT_BUILD_QMAKE && !QT_NO_SETTINGS diff --git a/src/gui/text/qfontdatabase.cpp b/src/gui/text/qfontdatabase.cpp index ba3b5eb7af..a3a3f20b18 100644 --- a/src/gui/text/qfontdatabase.cpp +++ b/src/gui/text/qfontdatabase.cpp @@ -663,11 +663,8 @@ struct QtFontDesc static void initFontDef(const QtFontDesc &desc, const QFontDef &request, QFontDef *fontDef, bool multi) { fontDef->family = desc.family->name; - if (! desc.foundry->name.isEmpty() && desc.family->count > 1) { - fontDef->family += QString::fromLatin1(" ["); - fontDef->family += desc.foundry->name; - fontDef->family += QLatin1Char(']'); - } + if (! desc.foundry->name.isEmpty() && desc.family->count > 1) + fontDef->family += QLatin1String(" [") + desc.foundry->name + QLatin1Char(']'); if (desc.style->smoothScalable || QGuiApplicationPrivate::platformIntegration()->fontDatabase()->fontsAlwaysScalable() diff --git a/src/gui/text/qplatformfontdatabase.cpp b/src/gui/text/qplatformfontdatabase.cpp index 0d7cb204ff..b83affecdc 100644 --- a/src/gui/text/qplatformfontdatabase.cpp +++ b/src/gui/text/qplatformfontdatabase.cpp @@ -395,10 +395,8 @@ void QPlatformFontDatabase::releaseHandle(void *handle) QString QPlatformFontDatabase::fontDir() const { QString fontpath = QString::fromLocal8Bit(qgetenv("QT_QPA_FONTDIR")); - if (fontpath.isEmpty()) { - fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath); - fontpath += QLatin1String("/fonts"); - } + if (fontpath.isEmpty()) + fontpath = QLibraryInfo::location(QLibraryInfo::LibrariesPath) + QLatin1String("/fonts"); return fontpath; } diff --git a/src/platformsupport/themes/qabstractfileiconengine.cpp b/src/platformsupport/themes/qabstractfileiconengine.cpp index 19a8eee47b..192ed00510 100644 --- a/src/platformsupport/themes/qabstractfileiconengine.cpp +++ b/src/platformsupport/themes/qabstractfileiconengine.cpp @@ -73,8 +73,7 @@ QPixmap QAbstractFileIconEngine::pixmap(const QSize &size, QIcon::Mode mode, if (key.isEmpty()) return filePixmap(size, mode, state); - key += QLatin1Char('_'); - key += QString::number(size.width()); + key += QLatin1Char('_') + QString::number(size.width()); QPixmap result; if (!QPixmapCache::find(key, result)) { diff --git a/src/plugins/platforms/xcb/qxcbmime.cpp b/src/plugins/platforms/xcb/qxcbmime.cpp index 4803c14c4c..749906d1e8 100644 --- a/src/plugins/platforms/xcb/qxcbmime.cpp +++ b/src/plugins/platforms/xcb/qxcbmime.cpp @@ -121,9 +121,7 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa // so QXcbConnection::atomName() has to be used. if (atomName == QLatin1String("text/uri-list") && connection->atomName(a) == "text/x-moz-url") { - const QByteArray uri = data->split('\n').first(); - QString mozUri = QString::fromLatin1(uri, uri.size()); - mozUri += QLatin1Char('\n'); + const QString mozUri = QLatin1String(data->split('\n').constFirst()) + QLatin1Char('\n'); *data = QByteArray(reinterpret_cast(mozUri.utf16()), mozUri.length() * 2); } else if (atomName == QLatin1String("application/x-color")) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index e4c92c5206..a9675935f4 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -61,8 +61,7 @@ QXcbVirtualDesktop::QXcbVirtualDesktop(QXcbConnection *connection, xcb_screen_t , m_number(number) , m_xSettings(Q_NULLPTR) { - QByteArray cmAtomName("_NET_WM_CM_S"); - cmAtomName += QByteArray::number(m_number); + const QByteArray cmAtomName = "_NET_WM_CM_S" + QByteArray::number(m_number); m_net_wm_cm_atom = connection->internAtom(cmAtomName.constData()); m_compositingActive = connection->getSelectionOwner(m_net_wm_cm_atom); diff --git a/src/tools/rcc/rcc.cpp b/src/tools/rcc/rcc.cpp index 3156df3f30..18772d2816 100644 --- a/src/tools/rcc/rcc.cpp +++ b/src/tools/rcc/rcc.cpp @@ -705,9 +705,7 @@ static void resourceDataFileMapRecursion(const RCCFileInfo *m_root, const QStrin const ChildConstIterator cend = m_root->m_children.constEnd(); for (ChildConstIterator it = m_root->m_children.constBegin(); it != cend; ++it) { const RCCFileInfo *child = it.value(); - QString childName = path; - childName += slash; - childName += child->m_name; + const QString childName = path + slash + child->m_name; if (child->m_flags & RCCFileInfo::Directory) { resourceDataFileMapRecursion(child, childName, m); } else { -- cgit v1.2.3