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 | |
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')
-rw-r--r-- | src/qml/compiler/qv4jsir_p.h | 30 | ||||
-rw-r--r-- | src/qml/compiler/qv4ssa.cpp | 2 |
2 files changed, 25 insertions, 7 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 diff --git a/src/qml/compiler/qv4ssa.cpp b/src/qml/compiler/qv4ssa.cpp index 89101ad756..f20dbbf4fe 100644 --- a/src/qml/compiler/qv4ssa.cpp +++ b/src/qml/compiler/qv4ssa.cpp @@ -477,7 +477,7 @@ class DominatorTree d->vertex[d->N] = n; d->parent[n] = todo.parent; ++d->N; - const QVector<BasicBlock *> &out = function->basicBlock(n)->out; + const BasicBlock::OutgoingEdges &out = function->basicBlock(n)->out; for (int i = out.size() - 1; i > 0; --i) worklist.push_back(DFSTodo(out[i]->index(), n)); |