Speed up interceptor
Using QStringLiterals and explicit QByteArray ctors makes it possible for the compiler to skip the more expensive QString ctors and use very cheap ones. This should give the interceptor a nice speedup.
This commit is contained in:
parent
9f85a7dc11
commit
0435cc8b47
@ -30,7 +30,7 @@ QTEST_MAIN(PackageUrlInterceptorTest)
|
||||
|
||||
void PackageUrlInterceptorTest::loadAccessManager()
|
||||
{
|
||||
Plasma::Package pkg = Plasma::Package();
|
||||
const Plasma::Package &pkg = Plasma::Package();
|
||||
QQmlNetworkAccessManagerFactory* pui = PackageUrlInterceptor::createPackageAccessManagerFactory(pkg);
|
||||
QVERIFY(pui != 0);
|
||||
delete pui;
|
||||
|
@ -67,13 +67,13 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
//should never happen
|
||||
Q_ASSERT(!relativePath.isEmpty());
|
||||
|
||||
QStringList components = relativePath.split("/");
|
||||
QStringList components = relativePath.split(QLatin1Char('/'));
|
||||
//a path with less than 2 items should ever happen
|
||||
Q_ASSERT(components.count() >= 2);
|
||||
|
||||
components.pop_front();
|
||||
//obtain a string in the form foo/bar/baz.qml: ui/ gets discarded
|
||||
QString filename = components.join("/");
|
||||
const QString &filename = components.join("/");
|
||||
|
||||
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||
return QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||
@ -91,8 +91,8 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
||||
qDebug() << "Trying" << platform;
|
||||
|
||||
//search for a platformqml/ path sibling of this import path
|
||||
QString platformPath = import+QStringLiteral("/../platformqml/")+platform+path.path().mid(import.length());
|
||||
QFile f(platformPath);
|
||||
const QString &platformPath = import+QStringLiteral("/../platformqml/")+platform+path.path().mid(import.length());
|
||||
const QFile f(platformPath);
|
||||
|
||||
qDebug() << "Found a platform specific file:" << QUrl::fromLocalFile(platformPath)<<f.exists();
|
||||
if (f.exists()) {
|
||||
|
@ -44,28 +44,28 @@ public:
|
||||
{
|
||||
switch (type) {
|
||||
case QQmlAbstractUrlInterceptor::QmlFile:
|
||||
return "ui";
|
||||
return QByteArray("ui");
|
||||
case QQmlAbstractUrlInterceptor::JavaScriptFile:
|
||||
return "scripts";
|
||||
return QByteArray("scripts");
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//failed by type, let's try by extension
|
||||
const QString extension = fileName.mid(fileName.lastIndexOf(".") + 1).toLower();
|
||||
const QString extension = fileName.mid(fileName.lastIndexOf(QLatin1Char('.')) + 1).toLower();
|
||||
|
||||
if (extension == "svg" || extension == "svgz" ||
|
||||
extension == "png" || extension == "gif" ||
|
||||
extension == "jpg" || extension == "jpeg") {
|
||||
return "images";
|
||||
if (extension == QStringLiteral("svg") || extension == QStringLiteral("svgz") ||
|
||||
extension == QStringLiteral("png") || extension == QStringLiteral("gif") ||
|
||||
extension == QStringLiteral("jpg") || extension == QStringLiteral("jpeg")) {
|
||||
return QByteArray("images");
|
||||
//FIXME: are those necessary? are they *always* catched by type?
|
||||
} else if (extension == "js") {
|
||||
return "scripts";
|
||||
} else if (extension == "qml") {
|
||||
return "ui";
|
||||
} else if (extension == QStringLiteral("js")) {
|
||||
return QByteArray("scripts");
|
||||
} else if (extension == QStringLiteral("qml")) {
|
||||
return QByteArray("ui");
|
||||
//everything else, throw it in "data"
|
||||
} else {
|
||||
return "data";
|
||||
return QByteArray("data");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user