summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/qml/qdeclarativevme.cpp72
-rw-r--r--src/declarative/qml/qdeclarativevme_p.h32
2 files changed, 72 insertions, 32 deletions
diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp
index 06aed98..221e52c 100644
--- a/src/declarative/qml/qdeclarativevme.cpp
+++ b/src/declarative/qml/qdeclarativevme.cpp
@@ -74,6 +74,27 @@
QT_BEGIN_NAMESPACE
+// A simple stack wrapper around QVarLengthArray
+template<typename T>
+class QDeclarativeVMEStack : private QVarLengthArray<T, 128>
+{
+private:
+ typedef QVarLengthArray<T, 128> VLA;
+ int _index;
+
+public:
+ inline QDeclarativeVMEStack();
+ inline bool isEmpty() const;
+ inline const T &top() const;
+ inline void push(const T &o);
+ inline T pop();
+ inline int count() const;
+ inline const T &at(int index) const;
+};
+
+// We do this so we can forward declare the type in the qdeclarativevme_p.h header
+class QDeclarativeVMEObjectStack : public QDeclarativeVMEStack<QObject *> {};
+
QDeclarativeVME::QDeclarativeVME()
{
}
@@ -99,10 +120,12 @@ struct ListInstance
QDeclarativeListProperty<void> qListProperty;
};
+Q_DECLARE_TYPEINFO(ListInstance, Q_PRIMITIVE_TYPE | Q_MOVABLE_TYPE);
+
QObject *QDeclarativeVME::run(QDeclarativeContextData *ctxt, QDeclarativeCompiledData *comp,
int start, int count, const QBitField &bindingSkipList)
{
- QDeclarativeVMEStack<QObject *> stack;
+ QDeclarativeVMEObjectStack stack;
if (start == -1) start = 0;
if (count == -1) count = comp->bytecode.count();
@@ -121,7 +144,7 @@ void QDeclarativeVME::runDeferred(QObject *object)
QDeclarativeCompiledData *comp = data->deferredComponent;
int start = data->deferredIdx + 1;
int count = data->deferredComponent->bytecode.at(data->deferredIdx).defer.deferCount;
- QDeclarativeVMEStack<QObject *> stack;
+ QDeclarativeVMEObjectStack stack;
stack.push(object);
run(stack, ctxt, comp, start, count, QBitField());
@@ -143,7 +166,7 @@ static void removeBindingOnProperty(QObject *o, int index)
#define CLEAN_PROPERTY(o, index) if (fastHasBinding(o, index)) removeBindingOnProperty(o, index)
-QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack,
+QObject *QDeclarativeVME::run(QDeclarativeVMEObjectStack &stack,
QDeclarativeContextData *ctxt,
QDeclarativeCompiledData *comp,
int start, int count,
@@ -1054,5 +1077,48 @@ QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData
}
}
+template<typename T>
+QDeclarativeVMEStack<T>::QDeclarativeVMEStack()
+: _index(-1)
+{
+}
+
+template<typename T>
+bool QDeclarativeVMEStack<T>::isEmpty() const {
+ return _index == -1;
+}
+
+template<typename T>
+const T &QDeclarativeVMEStack<T>::top() const {
+ return at(_index);
+}
+
+template<typename T>
+void QDeclarativeVMEStack<T>::push(const T &o) {
+ _index++;
+
+ Q_ASSERT(_index <= VLA::size());
+ if (_index == VLA::size())
+ append(o);
+ else
+ VLA::data()[_index] = o;
+}
+
+template<typename T>
+T QDeclarativeVMEStack<T>::pop() {
+ Q_ASSERT(_index >= 0);
+ --_index;
+ return VLA::data()[_index + 1];
+}
+
+template<typename T>
+int QDeclarativeVMEStack<T>::count() const {
+ return _index + 1;
+}
+
+template<typename T>
+const T &QDeclarativeVMEStack<T>::at(int index) const {
+ return VLA::data()[index];
+}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qdeclarativevme_p.h b/src/declarative/qml/qdeclarativevme_p.h
index 6b7b93f..b7f110f 100644
--- a/src/declarative/qml/qdeclarativevme_p.h
+++ b/src/declarative/qml/qdeclarativevme_p.h
@@ -58,6 +58,7 @@
#include <QtCore/QString>
#include <QtCore/QStack>
+#include <QtCore/QVarLengthArray>
QT_BEGIN_NAMESPACE
@@ -67,34 +68,7 @@ class QDeclarativeCompiledData;
class QDeclarativeCompiledData;
class QDeclarativeContextData;
-template<typename T, int N = 128>
-class QDeclarativeVMEStack {
-public:
- QDeclarativeVMEStack() : index(-1), maxSize(N), data((T *)fixedData) {}
- ~QDeclarativeVMEStack() { if (data != (T *)fixedData) qFree(data); }
-
- bool isEmpty() const { return index == -1; }
- const T &top() const { return data[index]; }
- void push(const T &i) { ++index; if (index == maxSize) realloc(); data[index] = i; }
- const T &pop() { --index; return data[index + 1]; }
- int count() const { return index + 1; }
- const T &at(int idx) { return data[idx]; }
-
-private:
- void realloc() {
- maxSize += N;
- if (data != (T *)fixedData) {
- data = (T*)qRealloc(data, maxSize * sizeof(T));
- } else {
- data = (T*)qMalloc(maxSize * sizeof(T));
- }
- }
- int index;
- int maxSize;
- T *data;
- char fixedData[N * sizeof(T)];
-};
-
+class QDeclarativeVMEObjectStack;
class QDeclarativeVME
{
public:
@@ -109,7 +83,7 @@ public:
QList<QDeclarativeError> errors() const;
private:
- QObject *run(QDeclarativeVMEStack<QObject *> &,
+ QObject *run(QDeclarativeVMEObjectStack &,
QDeclarativeContextData *, QDeclarativeCompiledData *,
int start, int count,
const QBitField &);