diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2015-12-23 14:08:48 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-01-06 09:25:34 +0000 |
commit | 7ffb275c5756ef60187a0d7aec4dcb949ee89fd1 (patch) | |
tree | 37d319a5d3d12adcd9f0eb5739d3037e05b3208c /src/qml/compiler/qv4jsir_p.h | |
parent | 49f9797d2a2aab245a9866bc4563812a6e8c02e1 (diff) |
V4: Replace QVector with (Q)VarLengthArray in BasicBlock.
This prevents extra mallocs in nearly all cases, because the number of
incoming edges is not that big. The outgoing edge count has a maximum of
two.
Change-Id: I89195809952ce6087c5af51d717a4c2d8ac6b853
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/qml/compiler/qv4jsir_p.h')
-rw-r--r-- | src/qml/compiler/qv4jsir_p.h | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/src/qml/compiler/qv4jsir_p.h b/src/qml/compiler/qv4jsir_p.h index 514ba3b906..80869dd3e3 100644 --- a/src/qml/compiler/qv4jsir_p.h +++ b/src/qml/compiler/qv4jsir_p.h @@ -53,6 +53,7 @@ #include <QtCore/QString> #include <QtCore/QBitArray> #include <QtCore/qurl.h> +#include <QtCore/QVarLengthArray> #include <qglobal.h> #if defined(CONST) && defined(Q_OS_WIN) @@ -114,6 +115,23 @@ struct CJump; struct Ret; struct Phi; +template<class T, int Prealloc> +class VarLengthArray: public QVarLengthArray<T, Prealloc> +{ +public: + bool removeOne(const T &element) + { + for (int i = 0; i < this->size(); ++i) { + if (this->at(i) == element) { + this->remove(i); + return true; + } + } + + return false; + } +}; + // Flag pointer: // * The first flag indicates whether the meta object is final. // If final, then none of its properties themselves need to @@ -771,10 +789,13 @@ private: Q_DISABLE_COPY(BasicBlock) public: + typedef VarLengthArray<BasicBlock *, 4> IncomingEdges; + typedef VarLengthArray<BasicBlock *, 2> OutgoingEdges; + Function *function; BasicBlock *catchBlock; - QVector<BasicBlock *> in; - QVector<BasicBlock *> out; + IncomingEdges in; + OutgoingEdges out; QQmlJS::AST::SourceLocation nextLocation; BasicBlock(Function *function, BasicBlock *catcher) @@ -785,10 +806,7 @@ public: , _isExceptionHandler(false) , _groupStart(false) , _isRemoved(false) - { - in.reserve(2); - out.reserve(2); - } + {} ~BasicBlock(); const QVector<Stmt *> &statements() const |