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 <marc.mutz@kdab.com>
This commit is contained in:
Anton Kudryavtsev 2016-04-01 14:17:51 +03:00
parent 5e38706624
commit d42da86c96
6 changed files with 15 additions and 13 deletions

View File

@ -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"))) {

View File

@ -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);

View File

@ -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"))

View File

@ -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())

View File

@ -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=")))

View File

@ -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);