diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-01-12 21:55:51 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2015-01-16 21:12:49 +0100 |
commit | 8ffb79bbd214c239e414dc4e9cf4569b3219bdab (patch) | |
tree | c9cc7e596be2616f8c1211f4fb7623c9153cd7d6 /src/qml/jsapi/qjsvalue_p.h | |
parent | 9fe1588915b935298917a0c29593eeed70da682f (diff) |
Refactor persistent values
Use a page wise allocation mechanism for persistent
values. This significantly reduces memory consumption
of persistent values and also improves their performance
a lot.
Change-Id: I8499d2ca5bdd871e029f643ae605a94544558bb5
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsapi/qjsvalue_p.h')
-rw-r--r-- | src/qml/jsapi/qjsvalue_p.h | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/src/qml/jsapi/qjsvalue_p.h b/src/qml/jsapi/qjsvalue_p.h index 43a3a74e38..3d7afdbd75 100644 --- a/src/qml/jsapi/qjsvalue_p.h +++ b/src/qml/jsapi/qjsvalue_p.h @@ -52,6 +52,8 @@ #include <private/qv4engine_p.h> #include <private/qv4object_p.h> #include <private/qflagpointer_p.h> +#include <private/qv4mm_p.h> +#include <private/qv4persistent_p.h> QT_BEGIN_NAMESPACE @@ -59,30 +61,60 @@ QT_BEGIN_NAMESPACE \internal \class QJSValuePrivate */ -class Q_QML_PRIVATE_EXPORT QJSValuePrivate : public QV4::PersistentValuePrivate +class Q_QML_PRIVATE_EXPORT QJSValuePrivate { public: - QJSValuePrivate(QV4::ExecutionEngine *engine, const QV4::ValueRef v) - : PersistentValuePrivate(v.asReturnedValue(), engine) + QJSValuePrivate() + : refcount(1) + {} + QJSValuePrivate(QV4::ExecutionEngine *e, const QV4::ValueRef v) + : refcount(1), + persistent(e, v) { - Q_ASSERT(!value.isEmpty()); + Q_ASSERT(!v->isEmpty()); } - QJSValuePrivate(QV4::ReturnedValue v) - : PersistentValuePrivate(v) + QJSValuePrivate(QV4::ExecutionEngine *e, QV4::ReturnedValue v) + : refcount(1), + persistent(e, v) { - Q_ASSERT(!value.isEmpty()); } - QJSValuePrivate(const QString &s) - : PersistentValuePrivate(QV4::Primitive::emptyValue().asReturnedValue()), - unboundData(s) + explicit QJSValuePrivate(const QVariant &v) + : refcount(1), + unboundData(v) { } + bool checkEngine(QV4::ExecutionEngine *e) { + if (persistent.isEmpty()) + getValue(e); + return persistent.engine() == e; + } + QV4::ReturnedValue getValue(QV4::ExecutionEngine *e); static QJSValuePrivate *get(const QJSValue &v) { return v.d; } + QV4::ExecutionEngine *engine() const { return persistent.engine(); } + + void ref() { ++refcount; } + void deref() { + if (!--refcount) + delete this; + } + + QV4::Value *valueForData(QV4::Value *scratch) const { + QV4::Value *v = persistent.valueRef(); + if (v) + return v; + *scratch = primitiveValueForUnboundData(); + return (scratch->isEmpty() ? 0 : scratch); + } + QV4::Value primitiveValueForUnboundData() const; + int refcount; + QV4::PersistentValue persistent; QVariant unboundData; +private: + QJSValuePrivate(QV4::ReturnedValue v) Q_DECL_EQ_DELETE; }; QT_END_NAMESPACE |