summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-01-12 03:23:21 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-01-12 03:23:21 (GMT)
commita53008073216540bb5cfd40563e4b33ba139832c (patch)
tree6f965d77a0443d4632b8661b1708bafd67baadfa
parente6877a75a6be941d09cc57bfbadc6502528ae289 (diff)
downloadQt-a53008073216540bb5cfd40563e4b33ba139832c.zip
Qt-a53008073216540bb5cfd40563e4b33ba139832c.tar.gz
Qt-a53008073216540bb5cfd40563e4b33ba139832c.tar.bz2
Improve efficiency and correctness of qHash(QUrl), and use it in Declarative
rather than qHash(url.toString()). Similar corelib changes may come from 4.6 too.
-rw-r--r--src/corelib/io/qurl.cpp12
-rw-r--r--src/corelib/io/qurl.h1
-rw-r--r--src/declarative/declarative.pro2
-rw-r--r--src/declarative/qml/qmlcompositetypemanager.cpp24
-rw-r--r--src/declarative/qml/qmlcompositetypemanager_p.h4
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/xmlpatterns/type/qprimitives_p.h2
7 files changed, 30 insertions, 19 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 7211292..db072aa 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -350,8 +350,8 @@ public:
};
int stateFlags;
- QByteArray encodedNormalized;
- const QByteArray & normalized();
+ mutable QByteArray encodedNormalized;
+ const QByteArray & normalized() const;
mutable QUrlErrorInfo errorInfo;
QString createErrorString();
@@ -3850,6 +3850,9 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const
if (!QURL_HASFLAG(stateFlags, Parsed)) parse();
else ensureEncodedParts();
+ if (options==0x100) // private - see qHash(QUrl)
+ return normalized();
+
QByteArray url;
if (!(options & QUrl::RemoveScheme) && !scheme.isEmpty()) {
@@ -3920,12 +3923,13 @@ QByteArray QUrlPrivate::toEncoded(QUrl::FormattingOptions options) const
#define qToLower(ch) (((ch|32) >= 'a' && (ch|32) <= 'z') ? (ch|32) : ch)
-const QByteArray &QUrlPrivate::normalized()
+const QByteArray &QUrlPrivate::normalized() const
{
if (QURL_HASFLAG(stateFlags, QUrlPrivate::Normalized))
return encodedNormalized;
- QURL_SETFLAG(stateFlags, QUrlPrivate::Normalized);
+ QUrlPrivate *that = const_cast<QUrlPrivate *>(this);
+ QURL_SETFLAG(that->stateFlags, QUrlPrivate::Normalized);
QUrlPrivate tmp = *this;
tmp.scheme = tmp.scheme.toLower();
diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h
index f76d345..1189667 100644
--- a/src/corelib/io/qurl.h
+++ b/src/corelib/io/qurl.h
@@ -75,6 +75,7 @@ public:
RemovePath = 0x20,
RemoveQuery = 0x40,
RemoveFragment = 0x80,
+ // 0x100: private: normalized
StripTrailingSlash = 0x10000
};
diff --git a/src/declarative/declarative.pro b/src/declarative/declarative.pro
index 9cb45f6..86a0370 100644
--- a/src/declarative/declarative.pro
+++ b/src/declarative/declarative.pro
@@ -3,7 +3,7 @@ QPRO_PWD = $$PWD
QT = core gui xml script network
contains(QT_CONFIG, svg): QT += svg
contains(QT_CONFIG, opengl): QT += opengl
-DEFINES += QT_BUILD_DECLARATIVE_LIB
+DEFINES += QT_BUILD_DECLARATIVE_LIB QT_NO_URL_CAST_FROM_STRING
win32-msvc*|win32-icc:QMAKE_LFLAGS += /BASE:0x66000000
solaris-cc*:QMAKE_CXXFLAGS_RELEASE -= -O2
diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp
index ff786cf..29959cb 100644
--- a/src/declarative/qml/qmlcompositetypemanager.cpp
+++ b/src/declarative/qml/qmlcompositetypemanager.cpp
@@ -55,6 +55,12 @@
QT_BEGIN_NAMESPACE
+inline uint qHash(const QUrl &uri)
+{
+ return qHash(uri.toEncoded(QUrl::FormattingOption(0x100)));
+}
+
+
QmlCompositeTypeData::QmlCompositeTypeData()
: status(Invalid), errorType(NoError), component(0), compiledComponent(0)
{
@@ -165,14 +171,14 @@ QmlCompositeTypeManager::~QmlCompositeTypeManager()
QmlCompositeTypeData *QmlCompositeTypeManager::get(const QUrl &url)
{
- QmlCompositeTypeData *unit = components.value(url.toString());
+ QmlCompositeTypeData *unit = components.value(url);
if (!unit) {
unit = new QmlCompositeTypeData;
unit->status = QmlCompositeTypeData::Waiting;
unit->progress = 0.0;
unit->imports.setBaseUrl(url);
- components.insert(url.toString(), unit);
+ components.insert(url, unit);
loadSource(unit);
}
@@ -216,7 +222,7 @@ void QmlCompositeTypeManager::replyFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
- QmlCompositeTypeData *unit = components.value(reply->url().toString());
+ QmlCompositeTypeData *unit = components.value(reply->url());
Q_ASSERT(unit);
if (reply->error() != QNetworkReply::NoError) {
@@ -246,7 +252,7 @@ void QmlCompositeTypeManager::resourceReplyFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
- QmlCompositeTypeResource *resource = resources.value(reply->url().toString());
+ QmlCompositeTypeResource *resource = resources.value(reply->url());
Q_ASSERT(resource);
if (reply->error() != QNetworkReply::NoError) {
@@ -337,7 +343,7 @@ void QmlCompositeTypeManager::requestProgress(qint64 received, qint64 total)
return;
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
- QmlCompositeTypeData *unit = components.value(reply->url().toString());
+ QmlCompositeTypeData *unit = components.value(reply->url());
Q_ASSERT(unit);
unit->progress = qreal(received)/total;
@@ -523,13 +529,13 @@ int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit)
continue;
}
- QmlCompositeTypeData *urlUnit = components.value(url.toString());
+ QmlCompositeTypeData *urlUnit = components.value(url);
if (!urlUnit) {
urlUnit = new QmlCompositeTypeData;
urlUnit->status = QmlCompositeTypeData::Waiting;
urlUnit->imports.setBaseUrl(url);
- components.insert(url.toString(), urlUnit);
+ components.insert(url, urlUnit);
loadSource(urlUnit);
}
@@ -591,13 +597,13 @@ void QmlCompositeTypeManager::compile(QmlCompositeTypeData *unit)
for (int ii = 0; ii < resourceList.count(); ++ii) {
QUrl url = unit->imports.baseUrl().resolved(resourceList.at(ii));
- QmlCompositeTypeResource *resource = resources.value(url.toString());
+ QmlCompositeTypeResource *resource = resources.value(url);
if (!resource) {
resource = new QmlCompositeTypeResource;
resource->status = QmlCompositeTypeResource::Waiting;
resource->url = url.toString();
- resources.insert(resource->url, resource);
+ resources.insert(url, resource);
loadResource(resource);
}
diff --git a/src/declarative/qml/qmlcompositetypemanager_p.h b/src/declarative/qml/qmlcompositetypemanager_p.h
index 0169bff..89e2353 100644
--- a/src/declarative/qml/qmlcompositetypemanager_p.h
+++ b/src/declarative/qml/qmlcompositetypemanager_p.h
@@ -105,9 +105,9 @@ private:
int resolveTypes(QmlCompositeTypeData *);
QmlEngine *engine;
- typedef QHash<QString, QmlCompositeTypeData *> Components;
+ typedef QHash<QUrl, QmlCompositeTypeData *> Components;
Components components;
- typedef QHash<QString, QmlCompositeTypeResource *> Resources;
+ typedef QHash<QUrl, QmlCompositeTypeResource *> Resources;
Resources resources;
};
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index aca3f76..8d78cc7 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -667,7 +667,7 @@ QScriptValue QmlEnginePrivate::createComponent(QScriptContext *ctxt,
QString arg = ctxt->argument(0).toString();
if (arg.isEmpty())
return engine->nullValue();
- QUrl url = QUrl(context->resolvedUrl(arg));
+ QUrl url = QUrl(context->resolvedUrl(QUrl(arg)));
QmlComponent *c = new QmlComponent(activeEngine, url, activeEngine);
c->setCreationContext(context);
return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QmlComponent*>());
@@ -1135,7 +1135,7 @@ struct QmlEnginePrivate::ImportedNamespace {
if (mapvmaj<vmaj || vmin >= mapversions.mid(dot+1).toInt()) {
QStringRef mapfile = space2<0 ? QStringRef() : line.midRef(space2+1,line.length()-space2-1);
if (url_return)
- *url_return = url.resolved(mapfile.toString());
+ *url_return = url.resolved(QUrl(mapfile.toString()));
return true;
}
}
diff --git a/src/xmlpatterns/type/qprimitives_p.h b/src/xmlpatterns/type/qprimitives_p.h
index 01c04a1..4be89d9 100644
--- a/src/xmlpatterns/type/qprimitives_p.h
+++ b/src/xmlpatterns/type/qprimitives_p.h
@@ -88,7 +88,7 @@ namespace QPatternist
*/
inline uint qHash(const QUrl &uri)
{
- return qHash(uri.toString());
+ return qHash(uri.toEncoded(QUrl::FormattingOption(0x100)));
}
/**