diff options
author | Matthew Vogt <matthew.vogt@nokia.com> | 2012-05-04 08:32:45 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-17 08:58:45 +0200 |
commit | 43a6cc75886c662e63db440dd191cefa1fe956f3 (patch) | |
tree | cd3247453a0c2a59e0c5d3af11434d18761c2de4 /src/qml/qml/qqmltypeloader_p.h | |
parent | 9af1a7d0aee4f9ed48b2519779388830a8dd03e9 (diff) |
Add QQmlEngine::trimComponentCache()
Allow unused data in the engine's component cache to be safely discarded
so that the memory can be freed for other purposes.
Unloading of scripts that are no longer required after trimming unused
components is not yet supported.
Task-number: QTBUG-25653
Change-Id: I37bc9d5592eeb5edceeb34d010a555dcffd11cea
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src/qml/qml/qqmltypeloader_p.h')
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 66f4fd5081..ab700805c4 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -268,9 +268,8 @@ public: }; Q_DECLARE_FLAGS(Options, Option) - QQmlTypeData *get(const QUrl &url, Mode mode = PreferSynchronous); - QQmlTypeData *get(const QByteArray &, const QUrl &url, Options = None); - void clearCache(); + QQmlTypeData *getType(const QUrl &url, Mode mode = PreferSynchronous); + QQmlTypeData *getType(const QByteArray &, const QUrl &url, Options = None); QQmlScriptBlob *getScript(const QUrl &); QQmlQmldirData *getQmldir(const QUrl &); @@ -283,10 +282,44 @@ public: bool directoryExists(const QString &path); const QQmlDirParser *qmlDirParser(const QString &filePath, const QString &uriHint, QString *outUrl); + template<typename T> + void clearCache(T *o, void (T::*callback)(QQmlTypeData *)) { + TypedCallback<T> cb(o, callback); + clearCache(&TypedCallback<T>::redirect, &cb); + } + + template<typename T> + void trimCache(T *o, void (T::*callback)(QQmlTypeData *)) { + TypedCallback<T> cb(o, callback); + trimCache(&TypedCallback<T>::redirect, &cb); + } + + bool isTypeLoaded(const QUrl &url) const; + bool isScriptLoaded(const QUrl &url) const; + private: void addBundleNoLock(const QString &, const QString &); QString bundleIdForQmldir(const QString &qmldir, const QString &uriHint); + template<typename T> + struct TypedCallback + { + TypedCallback(T *object, void (T::*func)(QQmlTypeData *)) : o(object), mf(func) {} + + static void redirect(void *arg, QQmlTypeData *type) + { + TypedCallback<T> *self = reinterpret_cast<TypedCallback<T> *>(arg); + ((self->o)->*(self->mf))(type); + } + + private: + T *o; + void (T::*mf)(QQmlTypeData *); + }; + + void clearCache(void (*callback)(void *, QQmlTypeData *), void *); + void trimCache(void (*callback)(void *, QQmlTypeData *), void *); + struct DirParser : public QQmlDirParser { QString adjustedUrl; }; typedef QHash<QUrl, QQmlTypeData *> TypeCache; @@ -332,7 +365,12 @@ public: QQmlScriptBlob *script; }; +private: + friend class QQmlTypeLoader; + QQmlTypeData(const QUrl &, QQmlTypeLoader::Options, QQmlTypeLoader *); + +public: ~QQmlTypeData(); QQmlTypeLoader *typeLoader() const; @@ -397,8 +435,12 @@ private: // only created and destroyed in the main thread :) class Q_AUTOTEST_EXPORT QQmlScriptData : public QQmlCleanup, public QQmlRefCount { -public: +private: + friend class QQmlTypeLoader; + QQmlScriptData(); + +public: ~QQmlScriptData(); QUrl url; @@ -425,8 +467,12 @@ private: class Q_AUTOTEST_EXPORT QQmlScriptBlob : public QQmlDataBlob { -public: +private: + friend class QQmlTypeLoader; + QQmlScriptBlob(const QUrl &, QQmlTypeLoader *); + +public: ~QQmlScriptBlob(); struct ScriptReference @@ -463,9 +509,12 @@ private: class Q_AUTOTEST_EXPORT QQmlQmldirData : public QQmlDataBlob { -public: +private: + friend class QQmlTypeLoader; + QQmlQmldirData(const QUrl &); +public: const QQmlDirComponents &dirComponents() const; protected: @@ -473,7 +522,6 @@ protected: private: QQmlDirComponents m_components; - }; QQmlDataBlob::Data::Data() |