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.
This commit is contained in:
Volker Krause 2022-03-09 17:40:40 +01:00 committed by Nicolás Alvarez
parent ba2496ca12
commit 15611cacb9
2 changed files with 6 additions and 6 deletions

View file

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

View file

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