From 15611cacb94e3f4197b8039586b63b01a2f95d18 Mon Sep 17 00:00:00 2001 From: Volker Krause Date: Wed, 9 Mar 2022 17:40:40 +0100 Subject: [PATCH] Port from QStringRef to QStringView The QStringView::to[Number]() methods in Qt5 cause one extra allocation compared to the QStringRef counter-part. As long as we aren't on a hot path this is probably not worth the extra #ifdef though. --- src/keyboard_layout_switching.cpp | 2 +- src/libkwineffects/kwinglplatform.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/keyboard_layout_switching.cpp b/src/keyboard_layout_switching.cpp index 2a71192399..b0b509ed7d 100644 --- a/src/keyboard_layout_switching.cpp +++ b/src/keyboard_layout_switching.cpp @@ -282,7 +282,7 @@ ApplicationPolicy::ApplicationPolicy(KWin::Xkb* xkb, KWin::KeyboardLayout* layou const QStringList keyList = m_config.keyList().filter(keyPrefix); for (const QString& key : keyList) { m_layoutsRestored.insert( - key.midRef(keyPrefix.size()).toLatin1(), + QStringView(key).mid(keyPrefix.size()).toLatin1(), m_config.readEntry(key, 0)); } } diff --git a/src/libkwineffects/kwinglplatform.cpp b/src/libkwineffects/kwinglplatform.cpp index 01a4c962c4..858d7b1d40 100644 --- a/src/libkwineffects/kwinglplatform.cpp +++ b/src/libkwineffects/kwinglplatform.cpp @@ -225,7 +225,7 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) const QString chipset16 = QString::fromLatin1(chipset); QString name = extract(chipset16, QStringLiteral("HD [0-9]{4}")); // HD followed by a space and 4 digits if (!name.isEmpty()) { - const int id = name.rightRef(4).toInt(); + const int id = QStringView(name).right(4).toInt(); if (id == 6250 || id == 6310) // Palm return Evergreen; @@ -246,7 +246,7 @@ static ChipClass detectRadeonClass(const QByteArray &chipset) name = extract(chipset16, QStringLiteral("X[0-9]{3,4}")); // X followed by 3-4 digits if (!name.isEmpty()) { - const int id = name.midRef(1, -1).toInt(); + const int id = QStringView(name).mid(1, -1).toInt(); // X1xxx if (id >= 1300) @@ -290,7 +290,7 @@ static ChipClass detectNVidiaClass(const QString &chipset) { QString name = extract(chipset, QStringLiteral("\\bNV[0-9,A-F]{2}\\b")); // NV followed by two hexadecimal digits if (!name.isEmpty()) { - const int id = chipset.midRef(2, -1).toInt(nullptr, 16); // Strip the 'NV' from the id + const int id = QStringView(chipset).mid(2, -1).toInt(nullptr, 16); // Strip the 'NV' from the id switch(id & 0xf0) { case 0x00: @@ -341,7 +341,7 @@ static ChipClass detectNVidiaClass(const QString &chipset) if (!name[name.length() - 1].isDigit()) name.chop(1); - const int id = name.rightRef(4).toInt(); + const int id = QStringView(name).right(4).toInt(); if (id < 6000) return NV30; @@ -360,7 +360,7 @@ static ChipClass detectNVidiaClass(const QString &chipset) if (!name[name.length() - 1].isDigit()) name.chop(1); - const int id = name.rightRef(3).toInt(); + const int id = QStringView(name).right(3).toInt(); if (id >= 100 && id < 600) { if (id >= 400) return GF100;