aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4value.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2014-01-25 22:22:47 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-05 18:29:23 +0100
commit843202b6083f2b9d01391558b7e6e3e0d014cca6 (patch)
tree55fb1d2ee3e5c882ef9b70fc72eaeca0b7724d56 /src/qml/jsruntime/qv4value.cpp
parentd89e2698669db83f0b3591ac43f054aacc8bfc85 (diff)
Move PersistenValue and WeakValue into it's own file
They deserve having their own set of files, and it helps reduce dependencies. Change-Id: Ifd4394f88ef51cbccc61bf92dd20636f570141d9 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4value.cpp')
-rw-r--r--src/qml/jsruntime/qv4value.cpp210
1 files changed, 0 insertions, 210 deletions
diff --git a/src/qml/jsruntime/qv4value.cpp b/src/qml/jsruntime/qv4value.cpp
index 33084e0499..c91084caee 100644
--- a/src/qml/jsruntime/qv4value.cpp
+++ b/src/qml/jsruntime/qv4value.cpp
@@ -281,213 +281,3 @@ Object *Value::toObject(ExecutionContext *ctx) const
return __qmljs_convert_to_object(ctx, ValueRef::fromRawValue(this))->getPointer();
}
-
-PersistentValue::PersistentValue(const ValueRef val)
- : d(new PersistentValuePrivate(val.asReturnedValue()))
-{
-}
-
-PersistentValue::PersistentValue(ReturnedValue val)
- : d(new PersistentValuePrivate(val))
-{
-}
-
-PersistentValue::PersistentValue(const PersistentValue &other)
- : d(other.d)
-{
- if (d)
- d->ref();
-}
-
-PersistentValue &PersistentValue::operator=(const PersistentValue &other)
-{
- if (d == other.d)
- return *this;
-
- // the memory manager cleans up those with a refcount of 0
-
- if (d)
- d->deref();
- d = other.d;
- if (d)
- d->ref();
-
- return *this;
-}
-
-PersistentValue &PersistentValue::operator =(const ValueRef other)
-{
- if (!d) {
- d = new PersistentValuePrivate(other.asReturnedValue());
- return *this;
- }
- d = d->detach(other.asReturnedValue());
- return *this;
-}
-
-PersistentValue &PersistentValue::operator =(ReturnedValue other)
-{
- if (!d) {
- d = new PersistentValuePrivate(other);
- return *this;
- }
- d = d->detach(other);
- return *this;
-}
-
-PersistentValue::~PersistentValue()
-{
- if (d)
- d->deref();
-}
-
-WeakValue::WeakValue(const ValueRef val)
- : d(new PersistentValuePrivate(val.asReturnedValue(), /*engine*/0, /*weak*/true))
-{
-}
-
-WeakValue::WeakValue(const WeakValue &other)
- : d(other.d)
-{
- if (d)
- d->ref();
-}
-
-WeakValue::WeakValue(ReturnedValue val)
- : d(new PersistentValuePrivate(val, /*engine*/0, /*weak*/true))
-{
-}
-
-WeakValue &WeakValue::operator=(const WeakValue &other)
-{
- if (d == other.d)
- return *this;
-
- // the memory manager cleans up those with a refcount of 0
-
- if (d)
- d->deref();
- d = other.d;
- if (d)
- d->ref();
-
- return *this;
-}
-
-WeakValue &WeakValue::operator =(const ValueRef other)
-{
- if (!d) {
- d = new PersistentValuePrivate(other.asReturnedValue(), /*engine*/0, /*weak*/true);
- return *this;
- }
- d = d->detach(other.asReturnedValue(), /*weak*/true);
- return *this;
-}
-
-WeakValue &WeakValue::operator =(const ReturnedValue &other)
-{
- if (!d) {
- d = new PersistentValuePrivate(other, /*engine*/0, /*weak*/true);
- return *this;
- }
- d = d->detach(other, /*weak*/true);
- return *this;
-}
-
-
-WeakValue::~WeakValue()
-{
- if (d)
- d->deref();
-}
-
-void WeakValue::markOnce(ExecutionEngine *e)
-{
- if (!d)
- return;
- d->value.mark(e);
-}
-
-PersistentValuePrivate::PersistentValuePrivate(ReturnedValue v, ExecutionEngine *e, bool weak)
- : refcount(1)
- , weak(weak)
- , engine(e)
- , prev(0)
- , next(0)
-{
- value.val = v;
- init();
-}
-
-void PersistentValuePrivate::init()
-{
- if (!engine) {
- Managed *m = value.asManaged();
- if (!m)
- return;
-
- engine = m->engine();
- }
- if (engine && !prev) {
- PersistentValuePrivate **listRoot = weak ? &engine->memoryManager->m_weakValues : &engine->memoryManager->m_persistentValues;
-
- prev = listRoot;
- next = *listRoot;
- *prev = this;
- if (next)
- next->prev = &this->next;
- }
-}
-
-PersistentValuePrivate::~PersistentValuePrivate()
-{
-}
-
-void PersistentValuePrivate::removeFromList()
-{
- if (prev) {
- if (next)
- next->prev = prev;
- *prev = next;
- next = 0;
- prev = 0;
- }
-}
-
-void PersistentValuePrivate::deref()
-{
- // if engine is not 0, they are registered with the memory manager
- // and will get cleaned up in the next gc run
- if (!--refcount) {
- removeFromList();
- delete this;
- }
-}
-
-PersistentValuePrivate *PersistentValuePrivate::detach(const QV4::ReturnedValue val, bool weak)
-{
- if (refcount == 1) {
- value.val = val;
-
- Managed *m = value.asManaged();
- if (!prev) {
- if (m) {
- ExecutionEngine *engine = m->engine();
- if (engine) {
- PersistentValuePrivate **listRoot = weak ? &engine->memoryManager->m_weakValues : &engine->memoryManager->m_persistentValues;
- prev = listRoot;
- next = *listRoot;
- *prev = this;
- if (next)
- next->prev = &this->next;
- }
- }
- } else if (!m)
- removeFromList();
-
- return this;
- }
- --refcount;
- return new PersistentValuePrivate(val, engine, weak);
-}
-