diff options
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r-- | src/qmlcompiler/qdeferredpointer_p.h | 12 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsscope_p.h | 7 |
2 files changed, 9 insertions, 10 deletions
diff --git a/src/qmlcompiler/qdeferredpointer_p.h b/src/qmlcompiler/qdeferredpointer_p.h index 07875013fa..b8a06cc13c 100644 --- a/src/qmlcompiler/qdeferredpointer_p.h +++ b/src/qmlcompiler/qdeferredpointer_p.h @@ -50,7 +50,6 @@ class QDeferredFactory public: T create() const; bool isValid() const; - void clear(); }; template<typename T> @@ -79,8 +78,9 @@ public: operator QSharedPointer<T>() const { if (m_factory && m_factory->isValid()) { - const_cast<std::remove_const_t<T> &>(*m_data) = m_factory->create(); - m_factory->clear(); + Factory localFactory; + std::swap(localFactory, *m_factory); // Swap before executing, to avoid recursion + const_cast<std::remove_const_t<T> &>(*m_data) = localFactory.create(); } return m_data; } @@ -135,8 +135,10 @@ public: if (m_factory) { auto factory = m_factory.toStrongRef(); if (factory->isValid()) { - const_cast<std::remove_const_t<T> &>(*(m_data.toStrongRef())) = factory->create(); - factory->clear(); + Factory localFactory; + std::swap(localFactory, *factory); // Swap before executing, to avoid recursion + const_cast<std::remove_const_t<T> &>(*(m_data.toStrongRef())) + = localFactory.create(); } } return m_data; diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h index df7aad840d..90696166e4 100644 --- a/src/qmlcompiler/qqmljsscope_p.h +++ b/src/qmlcompiler/qqmljsscope_p.h @@ -60,6 +60,8 @@ template<> class QDeferredFactory<QQmlJSScope> { public: + QDeferredFactory() = default; + QDeferredFactory(QQmlJSImporter *importer, const QString &filePath) : m_filePath(filePath), m_importer(importer) {} @@ -71,11 +73,6 @@ public: return !m_filePath.isEmpty() && m_importer != nullptr; } - void clear() { - m_filePath.clear(); - m_importer = nullptr; - } - private: QString m_filePath; QQmlJSImporter *m_importer = nullptr; |