From 435c87186ff54ebfd481e41e07b9a136fbc87a20 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Thu, 20 Aug 2009 20:39:09 +0200 Subject: implement registered script values as a doubly linked list It's faster. --- src/script/api/qscriptengine.cpp | 38 +++++++++++++++++++++++++++----------- src/script/api/qscriptengine_p.h | 2 +- src/script/api/qscriptvalue.cpp | 2 +- src/script/api/qscriptvalue_p.h | 4 ++++ 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 9fc2f72..6fde08f 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -791,7 +791,7 @@ static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng) } // namespace QScript QScriptEnginePrivate::QScriptEnginePrivate() - : inEval(false) + : registeredScriptValues(0), inEval(false) { qMetaTypeId(); @@ -1139,11 +1139,10 @@ void QScriptEnginePrivate::mark() variantPrototype->mark(); { - QList::const_iterator it; - for (it = registeredScriptValues.constBegin(); it != registeredScriptValues.constEnd(); ++it) { - QScriptValuePrivate *val = *it; - if (val->isJSC() && !val->jscValue.marked()) - val->jscValue.mark(); + QScriptValuePrivate *it; + for (it = registeredScriptValues; it != 0; it = it->next) { + if (it->isJSC() && !it->jscValue.marked()) + it->jscValue.mark(); } } @@ -1365,19 +1364,36 @@ bool QScriptEnginePrivate::scriptDisconnect(JSC::JSValue signal, JSC::JSValue re void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) { - registeredScriptValues.append(value); + value->prev = 0; + value->next = registeredScriptValues; + if (registeredScriptValues) + registeredScriptValues->prev = value; + registeredScriptValues = value; } void QScriptEnginePrivate::unregisterScriptValue(QScriptValuePrivate *value) { - registeredScriptValues.removeOne(value); + if (value->prev) + value->prev->next = value->next; + if (value->next) + value->next->prev = value->prev; + if (value == registeredScriptValues) + registeredScriptValues = value->next; + value->prev = 0; + value->next = 0; } void QScriptEnginePrivate::detachAllRegisteredScriptValues() { - for (int i = 0; i < registeredScriptValues.size(); ++i) - registeredScriptValues.at(i)->detachFromEngine(); - registeredScriptValues.clear(); + QScriptValuePrivate *it; + QScriptValuePrivate *next; + for (it = registeredScriptValues; it != 0; it = next) { + it->detachFromEngine(); + next = it->next; + it->prev = 0; + it->next = 0; + } + registeredScriptValues = 0; } #ifdef QT_NO_QOBJECT diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 0d034f5..5979b9b 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -236,7 +236,7 @@ public: QList ownedAgents; QScriptEngineAgent *activeAgent; int agentLineNumber; - QList registeredScriptValues; + QScriptValuePrivate *registeredScriptValues; QHash m_typeInfos; int processEventsInterval; QScriptValue abortResult; diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index ad7efbd..7b28e37 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -275,7 +275,7 @@ qsreal ToInteger(qsreal n) } // namespace QScript -QScriptValuePrivate::QScriptValuePrivate() : engine(0) +QScriptValuePrivate::QScriptValuePrivate() : engine(0), prev(0), next(0) { ref = 0; } diff --git a/src/script/api/qscriptvalue_p.h b/src/script/api/qscriptvalue_p.h index a9abff2..e05259e 100644 --- a/src/script/api/qscriptvalue_p.h +++ b/src/script/api/qscriptvalue_p.h @@ -122,6 +122,10 @@ public: double numberValue; QString stringValue; + // linked list of engine's script values + QScriptValuePrivate *prev; + QScriptValuePrivate *next; + QBasicAtomicInt ref; }; -- cgit v0.12