Don't use QByteArrayLiteral in comparisons

For const char*s, operator== is overloaded, so comparing to a (C) string
literal is efficient, since qstrcmp doesn't require the length of the
strings to compare.

OTOH, QByteArrayLiteral, when not using RVO, litters the code with
QByteArray dtor calls, which are not inline. Worse, absent lambdas,
it even allocates memory.

So, just compare with a (C) string literal instead.

Change-Id: Id3bfdc89558ba51911f6317a7a73c287f96e6f24
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2014-10-08 10:26:27 +02:00
parent 05663e29d0
commit bf1df55846
7 changed files with 19 additions and 19 deletions

View File

@ -444,7 +444,7 @@ bool QSslCertificatePrivate::parseExtension(const QByteArray &data, QSslCertific
QAsn1Element val; QAsn1Element val;
bool supported = true; bool supported = true;
QVariant value; QVariant value;
if (oid == QByteArrayLiteral("1.3.6.1.5.5.7.1.1")) { if (oid == "1.3.6.1.5.5.7.1.1") {
// authorityInfoAccess // authorityInfoAccess
if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType) if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType)
return false; return false;
@ -463,12 +463,12 @@ bool QSslCertificatePrivate::parseExtension(const QByteArray &data, QSslCertific
} }
} }
value = result; value = result;
} else if (oid == QByteArrayLiteral("2.5.29.14")) { } else if (oid == "2.5.29.14") {
// subjectKeyIdentifier // subjectKeyIdentifier
if (!val.read(valElem.value()) || val.type() != QAsn1Element::OctetStringType) if (!val.read(valElem.value()) || val.type() != QAsn1Element::OctetStringType)
return false; return false;
value = colonSeparatedHex(val.value()).toUpper(); value = colonSeparatedHex(val.value()).toUpper();
} else if (oid == QByteArrayLiteral("2.5.29.19")) { } else if (oid == "2.5.29.19") {
// basicConstraints // basicConstraints
if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType) if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType)
return false; return false;
@ -488,7 +488,7 @@ bool QSslCertificatePrivate::parseExtension(const QByteArray &data, QSslCertific
return false; return false;
} }
value = result; value = result;
} else if (oid == QByteArrayLiteral("2.5.29.35")) { } else if (oid == "2.5.29.35") {
// authorityKeyIdentifier // authorityKeyIdentifier
if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType) if (!val.read(valElem.value()) || val.type() != QAsn1Element::SequenceType)
return false; return false;

View File

@ -624,16 +624,16 @@ QStringList QGenericUnixTheme::themeNames()
QStringList result; QStringList result;
if (QGuiApplication::desktopSettingsAware()) { if (QGuiApplication::desktopSettingsAware()) {
const QByteArray desktopEnvironment = QGuiApplicationPrivate::platformIntegration()->services()->desktopEnvironment(); const QByteArray desktopEnvironment = QGuiApplicationPrivate::platformIntegration()->services()->desktopEnvironment();
if (desktopEnvironment == QByteArrayLiteral("KDE")) { if (desktopEnvironment == "KDE") {
#ifndef QT_NO_SETTINGS #ifndef QT_NO_SETTINGS
result.push_back(QLatin1String(QKdeTheme::name)); result.push_back(QLatin1String(QKdeTheme::name));
#endif #endif
} else if (desktopEnvironment == QByteArrayLiteral("GNOME") || } else if (desktopEnvironment == "GNOME" ||
desktopEnvironment == QByteArrayLiteral("X-CINNAMON") || desktopEnvironment == "X-CINNAMON" ||
desktopEnvironment == QByteArrayLiteral("UNITY") || desktopEnvironment == "UNITY" ||
desktopEnvironment == QByteArrayLiteral("MATE") || desktopEnvironment == "MATE" ||
desktopEnvironment == QByteArrayLiteral("XFCE") || desktopEnvironment == "XFCE" ||
desktopEnvironment == QByteArrayLiteral("LXDE")) { // Gtk-based desktops desktopEnvironment == "LXDE") { // Gtk-based desktops
// prefer the GTK2 theme implementation with native dialogs etc. // prefer the GTK2 theme implementation with native dialogs etc.
result.push_back(QStringLiteral("gtk2")); result.push_back(QStringLiteral("gtk2"));
// fallback to the generic Gnome theme if loading the GTK2 theme fails // fallback to the generic Gnome theme if loading the GTK2 theme fails

View File

@ -127,7 +127,7 @@ void QQnxButtonEventNotifier::updateButtonStates()
for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) { for (int buttonId = bid_minus; buttonId < ButtonCount; ++buttonId) {
// Extract the new button state // Extract the new button state
QByteArray key = m_buttonKeys.at(buttonId); QByteArray key = m_buttonKeys.at(buttonId);
ButtonState newState = (fields.value(key) == QByteArrayLiteral("b_up") ? ButtonUp : ButtonDown); ButtonState newState = (fields.value(key) == "b_up" ? ButtonUp : ButtonDown);
// If state has changed, update our state and inject a keypress event // If state has changed, update our state and inject a keypress event
if (m_state[buttonId] != newState) { if (m_state[buttonId] != newState) {

View File

@ -336,9 +336,9 @@ QWindowsStaticOpenGLContext *QWindowsStaticOpenGLContext::create()
#if defined(QT_OPENGL_DYNAMIC) #if defined(QT_OPENGL_DYNAMIC)
const QByteArray requested = qgetenv("QT_OPENGL"); // angle, desktop, software const QByteArray requested = qgetenv("QT_OPENGL"); // angle, desktop, software
const bool angleRequested = QCoreApplication::testAttribute(Qt::AA_UseOpenGLES) || requested == QByteArrayLiteral("angle"); const bool angleRequested = QCoreApplication::testAttribute(Qt::AA_UseOpenGLES) || requested == "angle";
const bool desktopRequested = QCoreApplication::testAttribute(Qt::AA_UseDesktopOpenGL) || requested == QByteArrayLiteral("desktop"); const bool desktopRequested = QCoreApplication::testAttribute(Qt::AA_UseDesktopOpenGL) || requested == "desktop";
const bool softwareRequested = QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL) || requested == QByteArrayLiteral("software"); const bool softwareRequested = QCoreApplication::testAttribute(Qt::AA_UseSoftwareOpenGL) || requested == "software";
// If ANGLE is requested, use it, don't try anything else. // If ANGLE is requested, use it, don't try anything else.
if (angleRequested) { if (angleRequested) {

View File

@ -58,7 +58,7 @@ int QWindowsScaling::determineUiScaleFactor()
return 1; return 1;
const QByteArray envDevicePixelRatioEnv = qgetenv(devicePixelRatioEnvVar); const QByteArray envDevicePixelRatioEnv = qgetenv(devicePixelRatioEnvVar);
// Auto: Suggest a scale factor by checking monitor resolution. // Auto: Suggest a scale factor by checking monitor resolution.
if (envDevicePixelRatioEnv == QByteArrayLiteral("auto")) { if (envDevicePixelRatioEnv == "auto") {
const int maxResolution = QWindowsScreen::maxMonitorHorizResolution(); const int maxResolution = QWindowsScreen::maxMonitorHorizResolution();
return maxResolution > 180 ? maxResolution / 96 : 1; return maxResolution > 180 ? maxResolution / 96 : 1;
} }

View File

@ -277,9 +277,9 @@ public:
static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice) static QPrint::DuplexMode ppdChoiceToDuplexMode(const QByteArray &choice)
{ {
if (choice == QByteArrayLiteral("DuplexTumble")) if (choice == "DuplexTumble")
return QPrint::DuplexShortSide; return QPrint::DuplexShortSide;
else if (choice == QByteArrayLiteral("DuplexNoTumble")) else if (choice == "DuplexNoTumble")
return QPrint::DuplexLongSide; return QPrint::DuplexLongSide;
else // None or SimplexTumble or SimplexNoTumble else // None or SimplexTumble or SimplexNoTumble
return QPrint::DuplexNone; return QPrint::DuplexNone;

View File

@ -3254,7 +3254,7 @@ bool QWizard::nativeEvent(const QByteArray &eventType, void *message, long *resu
{ {
#if !defined(QT_NO_STYLE_WINDOWSVISTA) #if !defined(QT_NO_STYLE_WINDOWSVISTA)
Q_D(QWizard); Q_D(QWizard);
if (d->isVistaThemeEnabled() && eventType == QByteArrayLiteral("windows_generic_MSG")) { if (d->isVistaThemeEnabled() && eventType == "windows_generic_MSG") {
MSG *windowsMessage = static_cast<MSG *>(message); MSG *windowsMessage = static_cast<MSG *>(message);
const bool winEventResult = d->vistaHelper->handleWinEvent(windowsMessage, result); const bool winEventResult = d->vistaHelper->handleWinEvent(windowsMessage, result);
if (QVistaHelper::vistaState() != d->vistaState) { if (QVistaHelper::vistaState() != d->vistaState) {