From ecb1a20324b53bd0cf60da18bde6f7a56f4567d3 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 29 Jul 2011 12:27:54 +1000 Subject: [PATCH] Fix alias warnings in QDeclarativeVME Task-number: QTBUG-19736 QTBUG-19693 Change-Id: Ieab2c7274852b39fc4222132dedc738ab663d4f9 Reviewed-on: http://codereview.qt.nokia.com/2361 Reviewed-by: Martin Jones --- src/declarative/qml/qdeclarativevme.cpp | 74 +++++++++++++++++++++++++++++- src/declarative/qml/qdeclarativevme_p.h | 31 +------------ 2 files changed, 73 insertions(+), 32 deletions(-) diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 96b71ac..3b7abe6 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -73,10 +73,32 @@ #include #include #include +#include #include QT_BEGIN_NAMESPACE +// A simple stack wrapper around QVarLengthArray +template +class QDeclarativeVMEStack : private QVarLengthArray +{ +private: + typedef QVarLengthArray 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 {}; + QDeclarativeVME::QDeclarativeVME() { } @@ -102,10 +124,12 @@ struct ListInstance QDeclarativeListProperty qListProperty; }; +Q_DECLARE_TYPEINFO(ListInstance, Q_PRIMITIVE_TYPE | Q_MOVABLE_TYPE); + QObject *QDeclarativeVME::run(QDeclarativeContextData *ctxt, QDeclarativeCompiledData *comp, int start, const QBitField &bindingSkipList) { - QDeclarativeVMEStack stack; + QDeclarativeVMEObjectStack stack; if (start == -1) start = 0; @@ -122,7 +146,7 @@ void QDeclarativeVME::runDeferred(QObject *object) QDeclarativeContextData *ctxt = data->context; QDeclarativeCompiledData *comp = data->deferredComponent; int start = data->deferredIdx; - QDeclarativeVMEStack stack; + QDeclarativeVMEObjectStack stack; stack.push(object); run(stack, ctxt, comp, start, QBitField()); @@ -152,7 +176,7 @@ static void removeBindingOnProperty(QObject *o, int index) #define CLEAN_PROPERTY(o, index) if (fastHasBinding(o, index)) removeBindingOnProperty(o, index) -QObject *QDeclarativeVME::run(QDeclarativeVMEStack &stack, +QObject *QDeclarativeVME::run(QDeclarativeVMEObjectStack &stack, QDeclarativeContextData *ctxt, QDeclarativeCompiledData *comp, int start, const QBitField &bindingSkipList) @@ -1069,4 +1093,48 @@ v8::Persistent QDeclarativeVME::run(QDeclarativeContextData *parentC return rv; } +template +QDeclarativeVMEStack::QDeclarativeVMEStack() +: _index(-1) +{ +} + +template +bool QDeclarativeVMEStack::isEmpty() const { + return _index == -1; +} + +template +const T &QDeclarativeVMEStack::top() const { + return at(_index); +} + +template +void QDeclarativeVMEStack::push(const T &o) { + _index++; + + Q_ASSERT(_index <= VLA::size()); + if (_index == VLA::size()) + append(o); + else + VLA::data()[_index] = o; +} + +template +T QDeclarativeVMEStack::pop() { + Q_ASSERT(_index >= 0); + --_index; + return VLA::data()[_index + 1]; +} + +template +int QDeclarativeVMEStack::count() const { + return _index + 1; +} + +template +const T &QDeclarativeVMEStack::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 dd23f1c..5312e7e 100644 --- a/src/declarative/qml/qdeclarativevme_p.h +++ b/src/declarative/qml/qdeclarativevme_p.h @@ -69,34 +69,7 @@ class QDeclarativeScriptData; class QDeclarativeCompiledData; class QDeclarativeCompiledData; class QDeclarativeContextData; - -template -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 { @@ -114,7 +87,7 @@ public: private: v8::Persistent run(QDeclarativeContextData *, QDeclarativeScriptData *); - QObject *run(QDeclarativeVMEStack &, + QObject *run(QDeclarativeVMEObjectStack &, QDeclarativeContextData *, QDeclarativeCompiledData *, int start, const QBitField &); QList vmeErrors; -- 1.7.2.5