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()
|
void PackageUrlInterceptorTest::loadAccessManager()
|
||||||
{
|
{
|
||||||
Plasma::Package pkg = Plasma::Package();
|
const Plasma::Package &pkg = Plasma::Package();
|
||||||
QQmlNetworkAccessManagerFactory* pui = PackageUrlInterceptor::createPackageAccessManagerFactory(pkg);
|
QQmlNetworkAccessManagerFactory* pui = PackageUrlInterceptor::createPackageAccessManagerFactory(pkg);
|
||||||
QVERIFY(pui != 0);
|
QVERIFY(pui != 0);
|
||||||
delete pui;
|
delete pui;
|
||||||
|
@ -67,13 +67,13 @@ QUrl PackageUrlInterceptor::intercept(const QUrl &path, QQmlAbstractUrlIntercept
|
|||||||
//should never happen
|
//should never happen
|
||||||
Q_ASSERT(!relativePath.isEmpty());
|
Q_ASSERT(!relativePath.isEmpty());
|
||||||
|
|
||||||
QStringList components = relativePath.split("/");
|
QStringList components = relativePath.split(QLatin1Char('/'));
|
||||||
//a path with less than 2 items should ever happen
|
//a path with less than 2 items should ever happen
|
||||||
Q_ASSERT(components.count() >= 2);
|
Q_ASSERT(components.count() >= 2);
|
||||||
|
|
||||||
components.pop_front();
|
components.pop_front();
|
||||||
//obtain a string in the form foo/bar/baz.qml: ui/ gets discarded
|
//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));
|
//qDebug() << "Returning" << QUrl::fromLocalFile(m_package.filePath(prefixForType(type, filename), filename));
|
||||||
return 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;
|
qDebug() << "Trying" << platform;
|
||||||
|
|
||||||
//search for a platformqml/ path sibling of this import path
|
//search for a platformqml/ path sibling of this import path
|
||||||
QString platformPath = import+QStringLiteral("/../platformqml/")+platform+path.path().mid(import.length());
|
const QString &platformPath = import+QStringLiteral("/../platformqml/")+platform+path.path().mid(import.length());
|
||||||
QFile f(platformPath);
|
const QFile f(platformPath);
|
||||||
|
|
||||||
qDebug() << "Found a platform specific file:" << QUrl::fromLocalFile(platformPath)<<f.exists();
|
qDebug() << "Found a platform specific file:" << QUrl::fromLocalFile(platformPath)<<f.exists();
|
||||||
if (f.exists()) {
|
if (f.exists()) {
|
||||||
|
@ -44,28 +44,28 @@ public:
|
|||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QQmlAbstractUrlInterceptor::QmlFile:
|
case QQmlAbstractUrlInterceptor::QmlFile:
|
||||||
return "ui";
|
return QByteArray("ui");
|
||||||
case QQmlAbstractUrlInterceptor::JavaScriptFile:
|
case QQmlAbstractUrlInterceptor::JavaScriptFile:
|
||||||
return "scripts";
|
return QByteArray("scripts");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//failed by type, let's try by extension
|
//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" ||
|
if (extension == QStringLiteral("svg") || extension == QStringLiteral("svgz") ||
|
||||||
extension == "png" || extension == "gif" ||
|
extension == QStringLiteral("png") || extension == QStringLiteral("gif") ||
|
||||||
extension == "jpg" || extension == "jpeg") {
|
extension == QStringLiteral("jpg") || extension == QStringLiteral("jpeg")) {
|
||||||
return "images";
|
return QByteArray("images");
|
||||||
//FIXME: are those necessary? are they *always* catched by type?
|
//FIXME: are those necessary? are they *always* catched by type?
|
||||||
} else if (extension == "js") {
|
} else if (extension == QStringLiteral("js")) {
|
||||||
return "scripts";
|
return QByteArray("scripts");
|
||||||
} else if (extension == "qml") {
|
} else if (extension == QStringLiteral("qml")) {
|
||||||
return "ui";
|
return QByteArray("ui");
|
||||||
//everything else, throw it in "data"
|
//everything else, throw it in "data"
|
||||||
} else {
|
} else {
|
||||||
return "data";
|
return QByteArray("data");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user