aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmltypeloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qml/qqmltypeloader.cpp')
-rw-r--r--src/qml/qml/qqmltypeloader.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp
index 7fed82f4a4..d164dc614f 100644
--- a/src/qml/qml/qqmltypeloader.cpp
+++ b/src/qml/qml/qqmltypeloader.cpp
@@ -1105,6 +1105,7 @@ void QQmlTypeLoader::loadThread(QQmlDataBlob *blob)
}
#define DATALOADER_MAXIMUM_REDIRECT_RECURSION 16
+#define TYPELOADER_MINIMUM_TRIM_THRESHOLD 64
void QQmlTypeLoader::networkReplyFinished(QNetworkReply *reply)
{
@@ -1581,7 +1582,8 @@ bool QQmlTypeLoader::QmldirContent::designerSupported() const
Constructs a new type loader that uses the given \a engine.
*/
QQmlTypeLoader::QQmlTypeLoader(QQmlEngine *engine)
- : m_engine(engine), m_thread(new QQmlTypeLoaderThread(this))
+ : m_engine(engine), m_thread(new QQmlTypeLoaderThread(this)),
+ m_typeCacheTrimThreshold(TYPELOADER_MINIMUM_TRIM_THRESHOLD)
{
}
@@ -1618,6 +1620,10 @@ QQmlTypeData *QQmlTypeLoader::getType(const QUrl &url, Mode mode)
QQmlTypeData *typeData = m_typeCache.value(url);
if (!typeData) {
+ // Trim before adding the new type, so that we don't immediately trim it away
+ if (m_typeCache.size() >= m_typeCacheTrimThreshold)
+ trimCache();
+
typeData = new QQmlTypeData(url, this);
// TODO: if (compiledData == 0), is it safe to omit this insertion?
m_typeCache.insert(url, typeData);
@@ -1922,12 +1928,22 @@ void QQmlTypeLoader::clearCache()
qDeleteAll(m_importQmlDirCache);
m_typeCache.clear();
+ m_typeCacheTrimThreshold = TYPELOADER_MINIMUM_TRIM_THRESHOLD;
m_scriptCache.clear();
m_qmldirCache.clear();
m_importDirCache.clear();
m_importQmlDirCache.clear();
}
+void QQmlTypeLoader::updateTypeCacheTrimThreshold()
+{
+ int size = m_typeCache.size();
+ if (size > m_typeCacheTrimThreshold)
+ m_typeCacheTrimThreshold = size * 2;
+ if (size < m_typeCacheTrimThreshold / 2)
+ m_typeCacheTrimThreshold = qMax(size * 2, TYPELOADER_MINIMUM_TRIM_THRESHOLD);
+}
+
void QQmlTypeLoader::trimCache()
{
while (true) {
@@ -1952,6 +1968,8 @@ void QQmlTypeLoader::trimCache()
}
}
+ updateTypeCacheTrimThreshold();
+
// TODO: release any scripts which are no longer referenced by any types
}