From d42da86c96cfef54f88b5897a76fb26044e4d449 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Fri, 1 Apr 2016 14:17:51 +0300 Subject: [PATCH] OpenGL, PlatformSupport: use QStringRef to optimize memory allocation Replace substring functions that return QString with corresponding functions that return QStringRef where it's possible. Create QString from QStringRef only where necessary. While touching the code, also port loops to C++11 style. Change-Id: Ib94d29b6ecec1cdab2604d0277a743e8b340be5e Reviewed-by: Marc Mutz --- src/opengl/qgl.cpp | 2 +- .../devicediscovery/qdevicediscovery_udev.cpp | 4 ++-- .../input/evdevkeyboard/qevdevkeyboardhandler.cpp | 6 +++--- .../input/evdevkeyboard/qevdevkeyboardmanager.cpp | 5 +++-- .../input/evdevmouse/qevdevmousehandler.cpp | 4 ++-- .../themes/genericunix/qgenericunixthemes.cpp | 7 ++++--- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index a8409346ba..5c8c1d58eb 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1264,7 +1264,7 @@ QGLFormat::OpenGLVersionFlags Q_AUTOTEST_EXPORT qOpenGLVersionFlagsFromString(co QGLFormat::OpenGLVersionFlags versionFlags = QGLFormat::OpenGL_Version_None; if (versionString.startsWith(QLatin1String("OpenGL ES"))) { - QStringList parts = versionString.split(QLatin1Char(' ')); + const auto parts = versionString.splitRef(QLatin1Char(' ')); if (parts.size() >= 3) { if (parts[2].startsWith(QLatin1String("1."))) { if (parts[1].endsWith(QLatin1String("-CM"))) { diff --git a/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp b/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp index b2e16a409a..f601a196ca 100644 --- a/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp +++ b/src/platformsupport/devicediscovery/qdevicediscovery_udev.cpp @@ -215,8 +215,8 @@ bool QDeviceDiscoveryUDev::checkDeviceType(udev_device *dev) return false; if ((m_types & Device_Keyboard) && (qstrcmp(udev_device_get_property_value(dev, "ID_INPUT_KEYBOARD"), "1") == 0 )) { - const char *capabilities_key = udev_device_get_sysattr_value(dev, "capabilities/key"); - QStringList val = QString::fromUtf8(capabilities_key).split(QLatin1Char(' '), QString::SkipEmptyParts); + const QString capabilities_key = QString::fromUtf8(udev_device_get_sysattr_value(dev, "capabilities/key")); + const auto val = capabilities_key.splitRef(QLatin1Char(' '), QString::SkipEmptyParts); if (!val.isEmpty()) { bool ok; unsigned long long keys = val.last().toULongLong(&ok, 16); diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index 150445f520..36de1e0c69 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp @@ -101,10 +101,10 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, bool enableCompose = false; int grab = 0; - QStringList args = specification.split(QLatin1Char(':')); - foreach (const QString &arg, args) { + const auto args = specification.splitRef(QLatin1Char(':')); + for (const QStringRef &arg : args) { if (arg.startsWith(QLatin1String("keymap="))) - keymapFile = arg.mid(7); + keymapFile = arg.mid(7).toString(); else if (arg == QLatin1String("disable-zap")) disableZap = true; else if (arg == QLatin1String("enable-compose")) diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp index 178578e5a2..ffe9f82325 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -135,9 +135,10 @@ void QEvdevKeyboardManager::loadKeymap(const QString &file) // Restore the default, which is either the built-in keymap or // the one given in the plugin spec. QString keymapFromSpec; - foreach (const QString &arg, m_spec.split(QLatin1Char(':'))) { + const auto specs = m_spec.splitRef(QLatin1Char(':')); + for (const QStringRef &arg : specs) { if (arg.startsWith(QLatin1String("keymap="))) - keymapFromSpec = arg.mid(7); + keymapFromSpec = arg.mid(7).toString(); } foreach (QEvdevKeyboardHandler *handler, m_keyboards) { if (keymapFromSpec.isEmpty()) diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp index 7f73a7ef94..382b9b1514 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp @@ -71,8 +71,8 @@ QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QStr int grab = 0; bool abs = false; - QStringList args = specification.split(QLatin1Char(':')); - foreach (const QString &arg, args) { + const auto args = specification.splitRef(QLatin1Char(':')); + for (const QStringRef &arg : args) { if (arg == QLatin1String("nocompress")) compression = false; else if (arg.startsWith(QLatin1String("dejitter="))) diff --git a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp index 720b032ea5..5e5c931c2c 100644 --- a/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp +++ b/src/platformsupport/themes/genericunix/qgenericunixthemes.cpp @@ -177,8 +177,9 @@ QStringList QGenericUnixTheme::xdgIconThemePaths() QString xdgDirString = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); if (xdgDirString.isEmpty()) xdgDirString = QLatin1String("/usr/local/share/:/usr/share/"); - foreach (const QString &xdgDir, xdgDirString.split(QLatin1Char(':'))) { - const QFileInfo xdgIconsDir(xdgDir + QStringLiteral("/icons")); + const auto xdgDirs = xdgDirString.splitRef(QLatin1Char(':')); + for (const QStringRef &xdgDir : xdgDirs) { + const QFileInfo xdgIconsDir(xdgDir + QLatin1String("/icons")); if (xdgIconsDir.isDir()) paths.append(xdgIconsDir.absoluteFilePath()); } @@ -626,7 +627,7 @@ public: { Q_ASSERT(!systemFont); const int split = gtkFontName.lastIndexOf(QChar::Space); - float size = gtkFontName.mid(split+1).toFloat(); + float size = gtkFontName.midRef(split + 1).toFloat(); QString fontName = gtkFontName.left(split); systemFont = new QFont(fontName, size);