Reenable shared bindings
authorAaron Kennedy <aaron.kennedy@nokia.com>
Mon, 20 Jun 2011 04:47:44 +0000 (14:47 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Mon, 20 Jun 2011 04:47:44 +0000 (14:47 +1000)
Now with extra "supports nested components" goodness.

src/declarative/qml/qdeclarativecompileddata.cpp
src/declarative/qml/qdeclarativecompiler.cpp
src/declarative/qml/qdeclarativecompiler_p.h
src/declarative/qml/qdeclarativeinstruction.cpp
src/declarative/qml/qdeclarativeinstruction_p.h
src/declarative/qml/qdeclarativevme.cpp
src/declarative/qml/v8/qv8bindings.cpp
src/declarative/qml/v8/qv8bindings_p.h
tests/auto/declarative/qdeclarativeinstruction/tst_qdeclarativeinstruction.cpp

index fc4b28b..d08a808 100644 (file)
@@ -129,7 +129,8 @@ QDeclarativeCompiledData::~QDeclarativeCompiledData()
     qDeleteAll(cachedPrograms);
     qDeleteAll(cachedClosures);
 
-    qPersistentDispose(v8bindings);
+    for (int ii = 0; ii < v8bindings.count(); ++ii)
+        qPersistentDispose(v8bindings[ii]);
 }
 
 void QDeclarativeCompiledData::clear()
index b653d10..bca9c65 100644 (file)
@@ -712,6 +712,7 @@ void QDeclarativeCompiler::compileTree(QDeclarativeParser::Object *tree)
         QDeclarativeInstruction bindings;
         bindings.setType(QDeclarativeInstruction::InitV8Bindings);
         bindings.initV8Bindings.program = output->indexForString(compileState.v8BindingProgram);
+        bindings.initV8Bindings.programIndex = compileState.v8BindingProgramIndex;
         bindings.initV8Bindings.line = compileState.v8BindingProgramLine;
         output->addInstruction(bindings);
     }
@@ -1220,6 +1221,7 @@ void QDeclarativeCompiler::genComponent(QDeclarativeParser::Object *obj)
         QDeclarativeInstruction bindings;
         bindings.setType(QDeclarativeInstruction::InitV8Bindings);
         bindings.initV8Bindings.program = output->indexForString(compileState.v8BindingProgram);
+        bindings.initV8Bindings.programIndex = compileState.v8BindingProgramIndex;
         bindings.initV8Bindings.line = compileState.v8BindingProgramLine;
         output->addInstruction(bindings);
     }
@@ -2973,7 +2975,7 @@ bool QDeclarativeCompiler::completeComponentBuild()
         bool isSharable = false;
         binding.rewrittenExpression = rewriteBinding(binding.expression.asAST(), expression, &isSharable);
 
-        if (0 && isSharable && !binding.property->isAlias /* See above re alias */ &&
+        if (isSharable && !binding.property->isAlias /* See above re alias */ &&
             binding.property->type != qMetaTypeId<QDeclarativeBinding*>()) {
             binding.dataType = BindingReference::V8;
             sharedBindings.append(&iter.value());
@@ -3017,6 +3019,8 @@ bool QDeclarativeCompiler::completeComponentBuild()
 
         compileState.v8BindingProgram = functionArray;
         compileState.v8BindingProgramLine = startLineNumber;
+        compileState.v8BindingProgramIndex = output->v8bindings.count();
+        output->v8bindings.append(v8::Persistent<v8::Array>());
     }
 
     if (bindingCompiler.isValid()) 
index 2756c3f..a1dfabb 100644 (file)
@@ -104,7 +104,7 @@ public:
     };
     QList<TypeReference> types;
 
-    v8::Persistent<v8::Array> v8bindings;
+    QList<v8::Persistent<v8::Array> > v8bindings;
 
     const QMetaObject *root;
     QAbstractDynamicMetaObject rootData;
@@ -309,6 +309,7 @@ private:
         QByteArray compiledBindingData;
         QString v8BindingProgram;
         int v8BindingProgramLine;
+        int v8BindingProgramIndex;
 
         QHash<QDeclarativeParser::Value *, BindingReference> bindings;
         QHash<QDeclarativeParser::Value *, BindingContext> signalExpressions;
index 4f64e4e..f99351b 100644 (file)
@@ -169,7 +169,7 @@ void QDeclarativeCompiledData::dump(QDeclarativeInstruction *instr, int idx)
         qWarning().nospace() << idx << "\t\t" << "ASSIGN_CUSTOMTYPE\t" << instr->assignCustomType.propertyIndex << "\t" << instr->assignCustomType.primitive << "\t" << instr->assignCustomType.type;
         break;
     case QDeclarativeInstruction::InitV8Bindings:
-        qWarning().nospace() << idx << "\t\t" << "INIT_V8_BINDING\t" << instr->initV8Bindings.program << "\t" << instr->initV8Bindings.line;
+        qWarning().nospace() << idx << "\t\t" << "INIT_V8_BINDING\t" << instr->initV8Bindings.program << "\t" << instr->initV8Bindings.programIndex << "\t" << instr->initV8Bindings.line;
         break;
     case QDeclarativeInstruction::StoreBinding:
         qWarning().nospace() << idx << "\t\t" << "STORE_BINDING\t" << instr->assignBinding.property << "\t" << instr->assignBinding.value << "\t" << instr->assignBinding.context;
index 5c51ea8..107d774 100644 (file)
@@ -187,7 +187,8 @@ union QDeclarativeInstruction
     struct instr_initV8Bindings {
         QML_INSTR_HEADER
         int program;
-        int line;
+        ushort programIndex;
+        ushort line;
     };
     struct instr_assignBinding {
         QML_INSTR_HEADER
index 377ef9d..95a8ca0 100644 (file)
@@ -661,7 +661,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
         QML_END_INSTR(BeginObject)
 
         QML_BEGIN_INSTR(InitV8Bindings)
-            ctxt->v8bindings = new QV8Bindings(primitives.at(instr.program), instr.line, comp, ctxt);
+            ctxt->v8bindings = new QV8Bindings(primitives.at(instr.program), instr.programIndex, 
+                                               instr.line, comp, ctxt);
         QML_END_INSTR(InitV8Bindings)
 
         QML_BEGIN_INSTR(StoreBinding)
index 424d06f..49cc00c 100644 (file)
@@ -162,7 +162,7 @@ void QV8BindingsPrivate::Binding::destroy()
     parent->q_func()->release();
 }
 
-QV8Bindings::QV8Bindings(const QString &program, int line,
+QV8Bindings::QV8Bindings(const QString &program, int index, int line,
                          QDeclarativeCompiledData *compiled, 
                          QDeclarativeContextData *context)
 : QObject(*(new QV8BindingsPrivate))
@@ -171,7 +171,7 @@ QV8Bindings::QV8Bindings(const QString &program, int line,
 
     QV8Engine *engine = QDeclarativeEnginePrivate::getV8Engine(context->engine);
 
-    if (compiled->v8bindings.IsEmpty()) {
+    if (compiled->v8bindings[index].IsEmpty()) {
         v8::HandleScope handle_scope;
         v8::Context::Scope scope(engine->context());
 
@@ -179,11 +179,11 @@ QV8Bindings::QV8Bindings(const QString &program, int line,
         v8::Local<v8::Value> result = script->Run(engine->contextWrapper()->sharedContext());
 
         if (result->IsArray()) 
-            compiled->v8bindings = qPersistentNew(v8::Local<v8::Array>::Cast(result));
+            compiled->v8bindings[index] = qPersistentNew(v8::Local<v8::Array>::Cast(result));
     }
 
     d->url = compiled->url;
-    d->functions = qPersistentNew(compiled->v8bindings);
+    d->functions = qPersistentNew(compiled->v8bindings[index]);
     d->bindingsCount = d->functions->Length();
     d->bindings = new QV8BindingsPrivate::Binding[d->bindingsCount];
     
index e99e3c8..f8a9407 100644 (file)
@@ -69,7 +69,7 @@ class QV8Bindings : public QObject,
                     public QDeclarativeRefCount
 {
 public:
-    QV8Bindings(const QString &program, int line,
+    QV8Bindings(const QString &program, int index, int line,
                 QDeclarativeCompiledData *compiled,
                 QDeclarativeContextData *context);
     virtual ~QV8Bindings();
index 3712db4..e6e87d1 100644 (file)
@@ -366,7 +366,7 @@ void tst_qdeclarativeinstruction::dump()
 
     {
         QDeclarativeInstruction i;
-        i.setType(QDeclarativeInstruction::StoreCompiledBinding);
+        i.setType(QDeclarativeInstruction::StoreV4Binding);
         i.assignBinding.property = 27;
         i.assignBinding.value = 2;
         i.assignBinding.context = 4;