diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-01-27 10:12:43 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-07 10:43:57 +0100 |
commit | 927a46b1af9728c770dabb82f0b2233600636d2a (patch) | |
tree | e323c9ca76fb766bbb271d03cad399f017555c6e /src/qml | |
parent | 694c083c0f83f02558f148c3b648d35efd9ed3c0 (diff) |
Rename Referenced to ManagedRef
First step of removing the templates here and turning this
into a class hierarchy. This is required, so we can move all
member methods into the Ref classes and make objects movable
during GC.
Change-Id: Ie14af07fd3e72a7d84a528d0042189ff12ba21bb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/jsruntime/qv4engine.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4engine_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4global_p.h | 11 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4managed_p.h | 60 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4persistent_p.h | 4 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4qobjectwrapper.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject.cpp | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4regexpobject_p.h | 2 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4scopedvalue_p.h | 27 | ||||
-rw-r--r-- | src/qml/jsruntime/qv4value_p.h | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmlvmemetaobject.cpp | 2 |
11 files changed, 53 insertions, 66 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp index 4c1d3fceb2..6de40f437c 100644 --- a/src/qml/jsruntime/qv4engine.cpp +++ b/src/qml/jsruntime/qv4engine.cpp @@ -560,7 +560,7 @@ Returned<RegExpObject> *ExecutionEngine::newRegExpObject(const QString &pattern, return newRegExpObject(re, global); } -Returned<RegExpObject> *ExecutionEngine::newRegExpObject(Referenced<RegExp> re, bool global) +Returned<RegExpObject> *ExecutionEngine::newRegExpObject(ManagedRef<RegExp> re, bool global) { RegExpObject *object = new (memoryManager) RegExpObject(this, re, global); return object->asReturned<RegExpObject>(); diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h index 6974835e8b..4fbef14f86 100644 --- a/src/qml/jsruntime/qv4engine_p.h +++ b/src/qml/jsruntime/qv4engine_p.h @@ -317,7 +317,7 @@ public: Returned<DateObject> *newDateObject(const QDateTime &dt); Returned<RegExpObject> *newRegExpObject(const QString &pattern, int flags); - Returned<RegExpObject> *newRegExpObject(Referenced<RegExp> re, bool global); + Returned<RegExpObject> *newRegExpObject(ManagedRef<RegExp> re, bool global); Returned<RegExpObject> *newRegExpObject(const QRegExp &re); Returned<Object> *newErrorObject(const ValueRef value); diff --git a/src/qml/jsruntime/qv4global_p.h b/src/qml/jsruntime/qv4global_p.h index 0337e336b9..d3764d0515 100644 --- a/src/qml/jsruntime/qv4global_p.h +++ b/src/qml/jsruntime/qv4global_p.h @@ -156,12 +156,11 @@ template<typename T> struct Returned; typedef Returned<String> ReturnedString; typedef Returned<Object> ReturnedObject; typedef Returned<FunctionObject> ReturnedFunctionObject; -template<typename T> struct Referenced; -typedef Referenced<Managed> ManagedRef; -typedef Referenced<String> StringRef; -typedef Referenced<Object> ObjectRef; -typedef Referenced<ArrayObject> ArrayObjectRef; -typedef Referenced<FunctionObject> FunctionObjectRef; +template<typename T> struct ManagedRef; +typedef ManagedRef<String> StringRef; +typedef ManagedRef<Object> ObjectRef; +typedef ManagedRef<ArrayObject> ArrayObjectRef; +typedef ManagedRef<FunctionObject> FunctionObjectRef; struct PersistentValuePrivate; class PersistentValue; diff --git a/src/qml/jsruntime/qv4managed_p.h b/src/qml/jsruntime/qv4managed_p.h index aa9fb0d0fb..ed4637e4f5 100644 --- a/src/qml/jsruntime/qv4managed_p.h +++ b/src/qml/jsruntime/qv4managed_p.h @@ -354,34 +354,36 @@ private: }; template<typename T> -struct Referenced { - // Important: Do NOT add a copy constructor to this class +struct ManagedRef { + // Important: Do NOT add a copy constructor to this class or any derived class // adding a copy constructor actually changes the calling convention, ie. // is not even binary compatible. Adding it would break assumptions made // in the jit'ed code. - Referenced(const Scoped<T> &v); - Referenced(TypedValue<T> &v) { ptr = &v; } - Referenced(Value &v) { + ManagedRef(const ScopedValue); + ManagedRef(const Scoped<T> &v); + ManagedRef(TypedValue<T> &v) { ptr = &v; } + ManagedRef(Value &v) { ptr = value_cast<T>(v) ? &v : 0; } - static Referenced fromValuePointer(Value *s) { - return Referenced(s); + static ManagedRef fromValuePointer(Value *s) { + ManagedRef r(s); + if (sizeof(void *) == 8) + r.ptr->val = 0; + else + *r.ptr = Value::fromManaged(0); + return r; } - Referenced &operator=(const Referenced &o) - { *ptr = *o.ptr; return *this; } - Referenced &operator=(T *t) + ManagedRef &operator=(T *t) { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif + if (sizeof(void *) == 4) + ptr->tag = Value::Managed_Type; ptr->m = t; return *this; } - Referenced &operator=(Returned<T> *t) { -#if QT_POINTER_SIZE == 4 - ptr->tag = Value::Managed_Type; -#endif + ManagedRef &operator=(Returned<T> *t) { + if (sizeof(void *) == 4) + ptr->tag = Value::Managed_Type; ptr->m = t->getPointer(); return *this; } @@ -406,38 +408,26 @@ struct Referenced { ReturnedValue asReturnedValue() const { return ptr ? ptr->val : Primitive::undefinedValue().asReturnedValue(); } operator Returned<T> *() const { return ptr ? Returned<T>::create(getPointer()) : 0; } - bool operator==(const Referenced<T> &other) { + bool operator==(const ManagedRef<T> &other) { if (ptr == other.ptr) return true; return ptr && other.ptr && ptr->m == other.ptr->m; } - bool operator!=(const Referenced<T> &other) { - if (ptr == other.ptr) - return false; - return !ptr || ptr->m != other.ptr->m; + bool operator!=(const ManagedRef<T> &other) { + return !operator==(other); } bool operator!() const { return !ptr || !ptr->managed(); } - static Referenced null() { return Referenced(Null); } + static ManagedRef null() { return ManagedRef((Value *)0); } bool isNull() const { return !ptr; } -private: - Referenced(Value *v) { +protected: + ManagedRef(Value *v) { ptr = v; -#if QT_POINTER_SIZE == 8 - ptr->val = 0; -#else - *ptr = Value::fromManaged(0); -#endif } - enum _Null { Null }; - Referenced(_Null) { ptr = 0; } Value *ptr; }; -typedef Referenced<Managed> ManagedRef; - - template<> inline Managed *value_cast(const Value &v) { return v.asManaged(); diff --git a/src/qml/jsruntime/qv4persistent_p.h b/src/qml/jsruntime/qv4persistent_p.h index 07e8ee9775..34cf9ba50d 100644 --- a/src/qml/jsruntime/qv4persistent_p.h +++ b/src/qml/jsruntime/qv4persistent_p.h @@ -85,13 +85,13 @@ public: template<typename T> PersistentValue(Returned<T> *obj); template<typename T> - PersistentValue(const Referenced<T> obj); + PersistentValue(const ManagedRef<T> obj); PersistentValue &operator=(const ValueRef other); PersistentValue &operator =(ReturnedValue other); template<typename T> PersistentValue &operator=(Returned<T> *obj); template<typename T> - PersistentValue &operator=(const Referenced<T> obj); + PersistentValue &operator=(const ManagedRef<T> obj); ~PersistentValue(); ReturnedValue value() const { diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp index 25b1aee281..4645efcbeb 100644 --- a/src/qml/jsruntime/qv4qobjectwrapper.cpp +++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp @@ -1702,7 +1702,7 @@ QV4::ReturnedValue CallArgument::toValue(QV8Engine *engine) } else if (type == -1 || type == qMetaTypeId<QVariant>()) { QVariant value = *qvariantPtr; QV4::ScopedValue rv(scope, engine->fromVariant(value)); - if (QV4::Referenced<QObjectWrapper> qobjectWrapper = rv->asRef<QV4::QObjectWrapper>()) { + if (QV4::ManagedRef<QObjectWrapper> qobjectWrapper = rv) { if (QObject *object = qobjectWrapper->object()) QQmlData::get(object, true)->setImplicitDestructible(); } diff --git a/src/qml/jsruntime/qv4regexpobject.cpp b/src/qml/jsruntime/qv4regexpobject.cpp index 3b1dc02194..35ba9bc483 100644 --- a/src/qml/jsruntime/qv4regexpobject.cpp +++ b/src/qml/jsruntime/qv4regexpobject.cpp @@ -80,7 +80,7 @@ RegExpObject::RegExpObject(InternalClass *ic) init(ic->engine); } -RegExpObject::RegExpObject(ExecutionEngine *engine, Referenced<RegExp> value, bool global) +RegExpObject::RegExpObject(ExecutionEngine *engine, ManagedRef<RegExp> value, bool global) : Object(engine->regExpClass) , value(value) , global(global) diff --git a/src/qml/jsruntime/qv4regexpobject_p.h b/src/qml/jsruntime/qv4regexpobject_p.h index cf699509cd..ce3d01725f 100644 --- a/src/qml/jsruntime/qv4regexpobject_p.h +++ b/src/qml/jsruntime/qv4regexpobject_p.h @@ -84,7 +84,7 @@ struct RegExpObject: Object { Property *lastIndexProperty(ExecutionContext *ctx); bool global; - RegExpObject(ExecutionEngine *engine, Referenced<RegExp> value, bool global); + RegExpObject(ExecutionEngine *engine, ManagedRef<RegExp> value, bool global); RegExpObject(ExecutionEngine *engine, const QRegExp &re); ~RegExpObject() {} diff --git a/src/qml/jsruntime/qv4scopedvalue_p.h b/src/qml/jsruntime/qv4scopedvalue_p.h index ce21404a53..9b9f062a9a 100644 --- a/src/qml/jsruntime/qv4scopedvalue_p.h +++ b/src/qml/jsruntime/qv4scopedvalue_p.h @@ -379,9 +379,9 @@ struct ScopedCallData { }; -typedef Referenced<String> StringRef; -typedef Referenced<Object> ObjectRef; -typedef Referenced<FunctionObject> FunctionObjectRef; +typedef ManagedRef<String> StringRef; +typedef ManagedRef<Object> ObjectRef; +typedef ManagedRef<FunctionObject> FunctionObjectRef; template<typename T> inline Scoped<T>::Scoped(const Scope &scope, const ValueRef &v) @@ -464,12 +464,6 @@ inline Returned<T> *Value::as() return Returned<T>::create(value_cast<T>(*this)); } -template<typename T> inline -Referenced<T> Value::asRef() -{ - return Referenced<T>(*this); -} - template<typename T> inline TypedValue<T> &TypedValue<T>::operator =(T *t) { @@ -492,7 +486,7 @@ inline TypedValue<T> &TypedValue<T>::operator=(Returned<T> *t) } template<typename T> -inline TypedValue<T> &TypedValue<T>::operator =(const Referenced<T> &v) +inline TypedValue<T> &TypedValue<T>::operator =(const ManagedRef<T> &v) { val = v.asReturnedValue(); return *this; @@ -524,7 +518,7 @@ PersistentValue::PersistentValue(Returned<T> *obj) } template<typename T> -inline PersistentValue::PersistentValue(const Referenced<T> obj) +inline PersistentValue::PersistentValue(const ManagedRef<T> obj) : d(new PersistentValuePrivate(*obj.ptr)) { } @@ -536,7 +530,7 @@ inline PersistentValue &PersistentValue::operator=(Returned<T> *obj) } template<typename T> -inline PersistentValue &PersistentValue::operator=(const Referenced<T> obj) +inline PersistentValue &PersistentValue::operator=(const ManagedRef<T> obj) { return operator=(*obj.ptr); } @@ -577,8 +571,15 @@ inline ValueRef &ValueRef::operator=(const ScopedValue &o) return *this; } + +template<typename T> +ManagedRef<T>::ManagedRef(const ScopedValue v) +{ + ptr = value_cast<T>(*v.ptr) ? v.ptr : 0; +} + template<typename T> -Referenced<T>::Referenced(const Scoped<T> &v) +ManagedRef<T>::ManagedRef(const Scoped<T> &v) : ptr(v.ptr) {} diff --git a/src/qml/jsruntime/qv4value_p.h b/src/qml/jsruntime/qv4value_p.h index 536057ef26..2aefcc4f30 100644 --- a/src/qml/jsruntime/qv4value_p.h +++ b/src/qml/jsruntime/qv4value_p.h @@ -356,9 +356,6 @@ struct Q_QML_EXPORT Value } template<typename T> inline Returned<T> *as(); - template<typename T> - inline Referenced<T> asRef(); - }; inline Managed *Value::asManaged() const @@ -436,7 +433,7 @@ struct TypedValue : public Value } TypedValue &operator =(T *t); TypedValue &operator =(const Scoped<T> &v); - TypedValue &operator =(const Referenced<T> &v); + TypedValue &operator =(const ManagedRef<T> &v); TypedValue &operator =(Returned<T> *t); TypedValue &operator =(const TypedValue<T> &t); diff --git a/src/qml/qml/qqmlvmemetaobject.cpp b/src/qml/qml/qqmlvmemetaobject.cpp index 0b966484ca..48893c1b7f 100644 --- a/src/qml/qml/qqmlvmemetaobject.cpp +++ b/src/qml/qml/qqmlvmemetaobject.cpp @@ -1086,7 +1086,7 @@ void QQmlVMEMetaObject::writeProperty(int id, const QVariant &value) // And, if the new value is a scarce resource, we need to ensure that it does not get // automatically released by the engine until no other references to it exist. QV4::ScopedValue newv(scope, QQmlEnginePrivate::get(ctxt->engine)->v8engine()->fromVariant(value)); - if (QV4::Referenced<QV4::VariantObject> v = newv->asRef<QV4::VariantObject>()) + if (QV4::ManagedRef<QV4::VariantObject> v = newv) v->addVmePropertyReference(); // Write the value and emit change signal as appropriate. |