diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2021-02-22 22:38:43 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2021-03-06 01:33:45 +0200 |
commit | ee35bdce8f6b08922b4c9e0c0c838e5f2c4a79ad (patch) | |
tree | 591898b2b603d84329fe335675d054ad3e28bbd2 /src/gui | |
parent | 36f12b207f6a08f6d5fda7d53246a8abe70edf63 (diff) | |
download | kconfig-ee35bdce8f6b08922b4c9e0c0c838e5f2c4a79ad.tar.gz kconfig-ee35bdce8f6b08922b4c9e0c0c838e5f2c4a79ad.tar.bz2 |
Optimise string operations a bit
- Use QString::arg(Args...) instead of .arg().arg()
- Use QLatin1String for string comparisons, should be faster
- Use QLatin1String::arg() for better readability
- Add the comment dfaure suggested in the MR, to explain why it's '2%'
then '%1' in a QString().arg().arg()
NO_CHANGELOG
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kconfiggroupgui.cpp | 10 | ||||
-rw-r--r-- | src/gui/kconfiggui.cpp | 2 | ||||
-rw-r--r-- | src/gui/kwindowconfig.cpp | 10 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/gui/kconfiggroupgui.cpp b/src/gui/kconfiggroupgui.cpp index 09c31590..ab0c268f 100644 --- a/src/gui/kconfiggroupgui.cpp +++ b/src/gui/kconfiggroupgui.cpp @@ -54,8 +54,9 @@ static bool readEntryGui(const QByteArray &data, const char *key, const QVariant const int count = list.count(); if (count != 3 && count != 4) { - const QString formatError = QStringLiteral(" (wrong format: expected '%1' items, read '%2')"); - qCritical() << qPrintable(errString()) << qPrintable(formatError.arg(QStringLiteral("3' or '4")).arg(count)); + qCritical() // + << qPrintable(errString()) // + << qPrintable(QStringLiteral(" (wrong format: expected '%1' items, read '%2')").arg(QStringLiteral("3' or '4")).arg(count)); return true; // return default } @@ -70,9 +71,10 @@ static bool readEntryGui(const QByteArray &data, const char *key, const QVariant } if (j < 0 || j > 255) { static const char *const components[] = {"red", "green", "blue", "alpha"}; - const QString boundsError = QStringLiteral(" (bounds error: %1 component %2)"); qCritical() << qPrintable(errString()) - << qPrintable(boundsError.arg(QLatin1String(components[i])).arg(j < 0 ? QStringLiteral("< 0") : QStringLiteral("> 255"))); + << qPrintable(QStringLiteral(" (bounds error: %1 component %2)") + .arg(QLatin1String(components[i]), // + j < 0 ? QStringLiteral("< 0") : QStringLiteral("> 255"))); return true; // return default } } diff --git a/src/gui/kconfiggui.cpp b/src/gui/kconfiggui.cpp index 938fbd93..cafe061d 100644 --- a/src/gui/kconfiggui.cpp +++ b/src/gui/kconfiggui.cpp @@ -13,7 +13,7 @@ static QString configName(const QString &id, const QString &key) { - return (QLatin1String("session/") + QGuiApplication::applicationName() + QLatin1Char('_') + id + QLatin1Char('_') + key); + return QLatin1String("session/%1_%2_%3").arg(QGuiApplication::applicationName(), id, key); } static KConfig *s_sessionConfig = nullptr; diff --git a/src/gui/kwindowconfig.cpp b/src/gui/kwindowconfig.cpp index a7697782..019e1aa2 100644 --- a/src/gui/kwindowconfig.cpp +++ b/src/gui/kwindowconfig.cpp @@ -37,7 +37,7 @@ static QString allConnectedScreens() static QString configFileString(const QRect &desk, const QString &key) { // We include resolution data to also save data on a per-resolution basis - const QString returnString = QStringLiteral("%1 %2 %3x%4").arg(allConnectedScreens()).arg(key).arg(desk.width()).arg(desk.height()); + const QString returnString = QStringLiteral("%1 %2 %3x%4").arg(allConnectedScreens(), key, QString::number(desk.width()), QString::number(desk.height())); return returnString; } @@ -136,7 +136,7 @@ void KWindowConfig::saveWindowPosition(const QWindow *window, KConfigGroup &conf { // On Wayland, the compositor is solely responsible for window positioning, // So this needs to be a no-op - if (!window || QGuiApplication::platformName() == QStringLiteral("wayland")) { + if (!window || QGuiApplication::platformName() == QLatin1String{"wayland"}) { return; } @@ -149,7 +149,7 @@ void KWindowConfig::restoreWindowPosition(QWindow *window, const KConfigGroup &c { // On Wayland, the compositor is solely responsible for window positioning, // So this needs to be a no-op - if (!window || QGuiApplication::platformName() == QStringLiteral("wayland")) { + if (!window || QGuiApplication::platformName() == QLatin1String{"wayland"}) { return; } @@ -166,8 +166,8 @@ void KWindowConfig::restoreWindowPosition(QWindow *window, const KConfigGroup &c // per-resolution information is not // TODO: Remove in KF6 or maybe even KF5.85 or something. It really only needs // to be here to transition existing users once they upgrade from 5.78 -> 5.79 - const int fallbackXPosition = config.readEntry(QStringLiteral("%1 XPosition %2").arg(allConnectedScreens()).arg(desk.width()), -1); - const int fallbackYPosition = config.readEntry(QStringLiteral("%1 YPosition %2").arg(allConnectedScreens()).arg(desk.height()), -1); + const int fallbackXPosition = config.readEntry(QStringLiteral("%1 XPosition %2").arg(allConnectedScreens(), QString::number(desk.width())), -1); + const int fallbackYPosition = config.readEntry(QStringLiteral("%1 YPosition %2").arg(allConnectedScreens(), QString::number(desk.height())), -1); const int xPos = config.readEntry(windowXPositionString(desk), fallbackXPosition); const int yPos = config.readEntry(windowYPositionString(desk), fallbackYPosition); |