From 5c50c19231943368ae1f07dbc63d57fac84445ca Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Tue, 5 Jun 2012 16:43:57 +1000 Subject: [PATCH] Don't cache visual data model v8 handles. The external resource is reference counted and resused irregardless of whether the handles are cached, and the reduction in the number of handles allocated needs to be comes at the cost of keeping persistent handle which have a negative impact on garbage collection. Change-Id: I92996faab08a0ff76d21e56dbdafdd7522882d2c Reviewed-by: Chris Adams --- src/quick/items/qquickvisualadaptormodel.cpp | 2 ++ src/quick/items/qquickvisualdatamodel.cpp | 39 +++++----------------------- src/quick/items/qquickvisualdatamodel_p_p.h | 2 -- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/src/quick/items/qquickvisualadaptormodel.cpp b/src/quick/items/qquickvisualadaptormodel.cpp index 1179973..f298346 100644 --- a/src/quick/items/qquickvisualadaptormodel.cpp +++ b/src/quick/items/qquickvisualadaptormodel.cpp @@ -401,6 +401,7 @@ public: } v8::Local data = type->constructor->NewInstance(); data->SetExternalResource(this); + ++scriptRef; return data; } @@ -559,6 +560,7 @@ public: } v8::Local data = type->constructor->NewInstance(); data->SetExternalResource(this); + ++scriptRef; return data; } }; diff --git a/src/quick/items/qquickvisualdatamodel.cpp b/src/quick/items/qquickvisualdatamodel.cpp index 0570941..2f31aca 100644 --- a/src/quick/items/qquickvisualdatamodel.cpp +++ b/src/quick/items/qquickvisualdatamodel.cpp @@ -1612,18 +1612,6 @@ int QQuickVisualDataModelItemMetaType::parseGroups(const v8::Local &g return groupFlags; } -void QQuickVisualDataModelItemMetaType::release_index(v8::Persistent object, void *data) -{ - static_cast(data)->indexHandle.Clear(); - qPersistentDispose(object); -} - -void QQuickVisualDataModelItemMetaType::release_model(v8::Persistent object, void *data) -{ - static_cast(data)->modelHandle.Clear(); - qPersistentDispose(object); -} - v8::Handle QQuickVisualDataModelItemMetaType::get_model( v8::Local, const v8::AccessorInfo &info) { @@ -1632,14 +1620,7 @@ v8::Handle QQuickVisualDataModelItemMetaType::get_model( if (!cacheItem->metaType->model) return v8::Undefined(); - if (cacheItem->modelHandle.IsEmpty()) { - cacheItem->modelHandle = qPersistentNew(cacheItem->get()); - cacheItem->modelHandle.MakeWeak(cacheItem, &release_model); - - ++cacheItem->scriptRef; - } - - return cacheItem->modelHandle; + return cacheItem->get(); } v8::Handle QQuickVisualDataModelItemMetaType::get_groups( @@ -1739,8 +1720,6 @@ QQuickVisualDataModelItem::~QQuickVisualDataModelItem() Q_ASSERT(scriptRef == 0); Q_ASSERT(objectRef == 0); Q_ASSERT(!object); - Q_ASSERT(indexHandle.IsEmpty()); - Q_ASSERT(modelHandle.IsEmpty()); if (incubationTask && metaType->model) QQuickVisualDataModelPrivate::get(metaType->model)->releaseIncubator(incubationTask); @@ -2257,17 +2236,13 @@ QQmlV8Handle QQuickVisualDataGroup::get(int index) model->m_compositor.setFlags(it, 1, Compositor::CacheFlag); } - if (cacheItem->indexHandle.IsEmpty()) { - if (model->m_cacheMetaType->constructor.IsEmpty()) - model->m_cacheMetaType->initializeConstructor(); - cacheItem->indexHandle = qPersistentNew(model->m_cacheMetaType->constructor->NewInstance()); - cacheItem->indexHandle->SetExternalResource(cacheItem); - cacheItem->indexHandle.MakeWeak(cacheItem, QQuickVisualDataModelItemMetaType::release_index); - - ++cacheItem->scriptRef; - } + if (model->m_cacheMetaType->constructor.IsEmpty()) + model->m_cacheMetaType->initializeConstructor(); + v8::Local handle = model->m_cacheMetaType->constructor->NewInstance(); + handle->SetExternalResource(cacheItem); + ++cacheItem->scriptRef; - return QQmlV8Handle::fromHandle(cacheItem->indexHandle); + return QQmlV8Handle::fromHandle(handle); } bool QQuickVisualDataGroupPrivate::parseIndex( diff --git a/src/quick/items/qquickvisualdatamodel_p_p.h b/src/quick/items/qquickvisualdatamodel_p_p.h index b88c8a4..e59b6dd 100644 --- a/src/quick/items/qquickvisualdatamodel_p_p.h +++ b/src/quick/items/qquickvisualdatamodel_p_p.h @@ -151,8 +151,6 @@ public: QObject *object; QQuickVisualDataModelAttached *attached; QVDMIncubationTask *incubationTask; - v8::Persistent indexHandle; - v8::Persistent modelHandle; int objectRef; int scriptRef; int groups; -- 2.7.4