diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-24 10:20:42 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-04-26 09:56:49 +0000 |
commit | f741956de935ab9f954afa53b32a167c0c7528ea (patch) | |
tree | 84bb99f97020f2b750d355325a6398e44e36dfeb /src | |
parent | 12a2c68789918637f7c28ef0b06d9e70b5fae0ca (diff) |
Clean up manual reference counting of blob dependencies
The manual addref() and then release() in notifyComplete() are hard to
read. It's simpler to let m_waitingFor store QQmlRefPointer instances,
at the expense of iteration code that's harer to read.
Change-Id: Idc51fbb1b24e0bd466381b9a1ad10fbd38fc8ac1
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 26 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader_p.h | 2 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 7023bb98c6..61bcf6a663 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -501,11 +501,12 @@ void QQmlDataBlob::addDependency(QQmlDataBlob *blob) if (!blob || blob->status() == Error || blob->status() == Complete || - status() == Error || status() == Complete || m_isDone || - m_waitingFor.contains(blob)) + status() == Error || status() == Complete || m_isDone) return; - blob->addref(); // balanced in notifyComplete + for (auto existingDep: qAsConst(m_waitingFor)) + if (existingDep.data() == blob) + return; m_data.setStatus(WaitingForDependencies); @@ -688,13 +689,11 @@ void QQmlDataBlob::tryDone() void QQmlDataBlob::cancelAllWaitingFor() { while (m_waitingFor.count()) { - QQmlDataBlob *blob = m_waitingFor.takeLast(); + QQmlRefPointer<QQmlDataBlob> blob = m_waitingFor.takeLast(); Q_ASSERT(blob->m_waitingOnMe.contains(this)); blob->m_waitingOnMe.removeOne(this); - - blob->release(); } } @@ -703,7 +702,8 @@ void QQmlDataBlob::notifyAllWaitingOnMe() while (m_waitingOnMe.count()) { QQmlDataBlob *blob = m_waitingOnMe.takeLast(); - Q_ASSERT(blob->m_waitingFor.contains(this)); + Q_ASSERT(std::any_of(blob->m_waitingFor.constBegin(), blob->m_waitingFor.constEnd(), + [this](const QQmlRefPointer<QQmlDataBlob> &waiting) { return waiting.data() == this; })); blob->notifyComplete(this); } @@ -711,13 +711,19 @@ void QQmlDataBlob::notifyAllWaitingOnMe() void QQmlDataBlob::notifyComplete(QQmlDataBlob *blob) { - Q_ASSERT(m_waitingFor.contains(blob)); Q_ASSERT(blob->status() == Error || blob->status() == Complete); QQmlCompilingProfiler prof(typeLoader()->profiler(), blob); m_inCallback = true; - m_waitingFor.removeOne(blob); + QQmlRefPointer<QQmlDataBlob> blobRef; + for (int i = 0; i < m_waitingFor.count(); ++i) { + if (m_waitingFor.at(i).data() == blob) { + blobRef = m_waitingFor.takeAt(i); + break; + } + } + Q_ASSERT(blobRef); if (blob->status() == Error) { dependencyError(blob); @@ -725,8 +731,6 @@ void QQmlDataBlob::notifyComplete(QQmlDataBlob *blob) dependencyComplete(blob); } - blob->release(); - if (!isError() && m_waitingFor.isEmpty()) allDependenciesDone(); diff --git a/src/qml/qml/qqmltypeloader_p.h b/src/qml/qml/qqmltypeloader_p.h index 11e211012d..2418f3f716 100644 --- a/src/qml/qml/qqmltypeloader_p.h +++ b/src/qml/qml/qqmltypeloader_p.h @@ -217,7 +217,7 @@ private: QList<QQmlDataBlob *> m_waitingOnMe; // List of QQmlDataBlob's that I am waiting for to complete. - QList<QQmlDataBlob *> m_waitingFor; + QVector<QQmlRefPointer<QQmlDataBlob>> m_waitingFor; int m_redirectCount:30; bool m_inCallback:1; |