From 306292db8eb1a647f13b91f8ebe18fc5bebf073e Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Wed, 7 Aug 2013 11:07:40 +0200 Subject: [PATCH] Fix needless conversion from char * to QString Converting the strings to UTF-16 unconditionally whenever the library is loaded is overkill. Anyhow, the literals are only passed to methods also accepting a QLatin1String, so we don't have to convert at all. Change-Id: I84e813ac989344bc2e359f340696423766392c93 Reviewed-by: Alan Alpert --- src/qml/qml/qqmlfile.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/qml/qml/qqmlfile.cpp b/src/qml/qml/qqmlfile.cpp index aaf2362..be9b011 100644 --- a/src/qml/qml/qqmlfile.cpp +++ b/src/qml/qml/qqmlfile.cpp @@ -60,12 +60,12 @@ Supports file://, qrc:/, bundle:// uris and whatever QNetworkAccessManager suppo QT_BEGIN_NAMESPACE -static QString qrc_string(QLatin1String("qrc")); -static QString file_string(QLatin1String("file")); -static QString bundle_string(QLatin1String("bundle")); +static char qrc_string[] = "qrc"; +static char file_string[] = "file"; +static char bundle_string[] = "bundle"; #if defined(Q_OS_ANDROID) -static QString assets_string(QLatin1String("assets")); +static char assets_string[] = "assets"; #endif class QQmlFilePrivate; @@ -493,13 +493,13 @@ bool QQmlFile::isSynchronous(const QUrl &url) { QString scheme = url.scheme(); - if ((scheme.length() == 4 && 0 == scheme.compare(file_string, Qt::CaseInsensitive)) || - (scheme.length() == 6 && 0 == scheme.compare(bundle_string, Qt::CaseInsensitive)) || - (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive))) { + if ((scheme.length() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) || + (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(bundle_string), Qt::CaseInsensitive)) || + (scheme.length() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) { return true; #if defined(Q_OS_ANDROID) - } else if (scheme.length() == 6 && 0 == scheme.compare(assets_string, Qt::CaseInsensitive)) { + } else if (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(assets_string), Qt::CaseInsensitive)) { return true; #endif @@ -525,19 +525,19 @@ bool QQmlFile::isSynchronous(const QString &url) if (f == QLatin1Char('f') || f == QLatin1Char('F')) { return url.length() >= 7 /* file:// */ && - url.startsWith(file_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); } else if (f == QLatin1Char('b') || f == QLatin1Char('B')) { return url.length() >= 9 /* bundle:// */ && - url.startsWith(bundle_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(bundle_string), Qt::CaseInsensitive) && url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/') && url[8] == QLatin1Char('/'); } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) { return url.length() >= 5 /* qrc:/ */ && - url.startsWith(qrc_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); } @@ -545,7 +545,7 @@ bool QQmlFile::isSynchronous(const QString &url) #if defined(Q_OS_ANDROID) else if (f == QLatin1Char('a') || f == QLatin1Char('A')) { return url.length() >= 8 /* assets:/ */ && - url.startsWith(assets_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive) && url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/'); } @@ -561,7 +561,7 @@ Bundle urls have a bundle:// scheme. */ bool QQmlFile::isBundle(const QString &url) { - return url.length() >= 9 && url.startsWith(bundle_string, Qt::CaseInsensitive) && + return url.length() >= 9 && url.startsWith(QLatin1String(bundle_string), Qt::CaseInsensitive) && url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/') && url[8] == QLatin1Char('/'); } @@ -574,7 +574,7 @@ bool QQmlFile::isBundle(const QUrl &url) { QString scheme = url.scheme(); - return scheme.length() == 6 && 0 == scheme.compare(bundle_string, Qt::CaseInsensitive); + return scheme.length() == 6 && 0 == scheme.compare(QLatin1String(bundle_string), Qt::CaseInsensitive); } /*! @@ -588,12 +588,12 @@ bool QQmlFile::isLocalFile(const QUrl &url) { QString scheme = url.scheme(); - if ((scheme.length() == 4 && 0 == scheme.compare(file_string, Qt::CaseInsensitive)) || - (scheme.length() == 3 && 0 == scheme.compare(qrc_string, Qt::CaseInsensitive))) { + if ((scheme.length() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) || + (scheme.length() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) { return true; #if defined(Q_OS_ANDROID) - } else if (scheme.length() == 6 && 0 == scheme.compare(assets_string, Qt::CaseInsensitive)) { + } else if (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(assets_string), Qt::CaseInsensitive)) { return true; #endif @@ -619,20 +619,20 @@ bool QQmlFile::isLocalFile(const QString &url) if (f == QLatin1Char('f') || f == QLatin1Char('F')) { return url.length() >= 7 /* file:// */ && - url.startsWith(file_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) && url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/'); } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) { return url.length() >= 5 /* qrc:/ */ && - url.startsWith(qrc_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) && url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/'); } #if defined(Q_OS_ANDROID) else if (f == QLatin1Char('a') || f == QLatin1Char('A')) { return url.length() >= 8 /* assets:/ */ && - url.startsWith(assets_string, Qt::CaseInsensitive) && + url.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive) && url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/'); } -- 2.7.4