diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-18 17:38:48 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-21 11:22:35 +0000 |
commit | f29566c5a41c127eacaf13f3dbfe4624e55bc83f (patch) | |
tree | 65af6e3512b5f3cad8f9839dad98d284e1620a5c /src/corelib | |
parent | 4440387b85bbed53f4b118b8098cc616b4e6c92a (diff) |
Prevent repeated instantiations of some qRegisterNormalizedMetaType<>s [1/N] (QtGui)
Create macros that wrap the magic developed in
7d63efc16f65f98c657caa90e0d7e9b72a879ade and apply it to all
Q_DECLARE_METATYPE invocations that show up in Clang -ftime-trace for
a PCH'ed QtGui build.
Effects on compile times:
Clang 10 -ftme-trace:
$ ClangBuildAnalyzer --analyze qtgui-before.trace | head -n6
Analyzing build trace from 'qtgui-before.trace'...
**** Time summary:
Compilation (523 times):
Parsing (frontend): 628.3 s
Codegen & opts (backend): 304.5 s
$ ClangBuildAnalyzer --analyze qtgui-after.trace | head -n6
Analyzing build trace from 'qtgui-after.trace'...
**** Time summary:
Compilation (523 times):
Parsing (frontend): 546.0 s
Codegen & opts (backend): 304.4 s
GCC 11 time (bash builtin):
before:
$ time for ((i=0; i < 3; ++i)) do touch src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done
real 4m13,539s
user 49m24,416s
sys 3m18,177s
after:
$ time for ((i=0; i < 3; ++i)) do touch src/gui/painting/qpolygon.h ; ninja libQt6Gui.so; done
real 3m55,697s
user 45m19,941s
sys 3m7,370s
Task-number: QTBUG-97601
Pick-to: 6.3
Change-Id: Ia8e37a58937568a7ed21cfeb4b27274deca4d53b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/global/qfloat16.cpp | 2 | ||||
-rw-r--r-- | src/corelib/global/qfloat16.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qfileinfo.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qstorageinfo.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qstorageinfo.h | 2 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 3 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 6 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 3 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 4 | ||||
-rw-r--r-- | src/corelib/kernel/qdeadlinetimer.cpp | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qdeadlinetimer.h | 2 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 1 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 32 | ||||
-rw-r--r-- | src/corelib/kernel/qsocketnotifier.cpp | 3 | ||||
-rw-r--r-- | src/corelib/kernel/qsocketnotifier.h | 5 | ||||
-rw-r--r-- | src/corelib/serialization/qcborcommon.cpp | 2 | ||||
-rw-r--r-- | src/corelib/serialization/qcborcommon.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qversionnumber.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qversionnumber.h | 4 |
20 files changed, 59 insertions, 25 deletions
diff --git a/src/corelib/global/qfloat16.cpp b/src/corelib/global/qfloat16.cpp index 834d82e0ea..9646943620 100644 --- a/src/corelib/global/qfloat16.cpp +++ b/src/corelib/global/qfloat16.cpp @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(qfloat16) + /*! \class qfloat16 \keyword 16-bit Floating Point Support diff --git a/src/corelib/global/qfloat16.h b/src/corelib/global/qfloat16.h index 59739fdcc1..a178563889 100644 --- a/src/corelib/global/qfloat16.h +++ b/src/corelib/global/qfloat16.h @@ -367,7 +367,7 @@ inline auto qHypot(qfloat16 x, qfloat16 y, qfloat16 z) QT_END_NAMESPACE -Q_DECLARE_METATYPE(qfloat16) +QT_DECL_METATYPE_EXTERN(qfloat16, Q_CORE_EXPORT) namespace std { template<> diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index da19ba625c..dcbfae0d3f 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QFileInfo) + QString QFileInfoPrivate::getFileName(QAbstractFileEngine::FileName name) const { if (cache_enabled && !fileNames[(int)name].isNull()) diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index b54a24e563..f2260db410 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -212,6 +212,6 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QFileInfo &); QT_END_NAMESPACE -Q_DECLARE_METATYPE(QFileInfo) +QT_DECL_METATYPE_EXTERN(QFileInfo, Q_CORE_EXPORT) #endif // QFILEINFO_H diff --git a/src/corelib/io/qstorageinfo.cpp b/src/corelib/io/qstorageinfo.cpp index 86b8ae0ac3..41abce8d84 100644 --- a/src/corelib/io/qstorageinfo.cpp +++ b/src/corelib/io/qstorageinfo.cpp @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QStorageInfo) + /*! \class QStorageInfo \inmodule QtCore diff --git a/src/corelib/io/qstorageinfo.h b/src/corelib/io/qstorageinfo.h index fc440fa05e..251635efa6 100644 --- a/src/corelib/io/qstorageinfo.h +++ b/src/corelib/io/qstorageinfo.h @@ -120,6 +120,6 @@ Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QStorageInfo &); QT_END_NAMESPACE -Q_DECLARE_METATYPE(QStorageInfo) +QT_DECL_METATYPE_EXTERN(QStorageInfo, Q_CORE_EXPORT) #endif // QSTORAGEINFO_H diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 2907cb66ae..c716648427 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -60,8 +60,7 @@ QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY(lcCheckIndex, "qt.core.qabstractitemmodel.checkindex") -int qRegisterNormalizedMetaType_QList_QModelIndex(const QByteArray &name) -{ return qRegisterNormalizedMetaTypeImplementation<QList<QModelIndex>>(name); } +QT_IMPL_METATYPE_EXTERN(QModelIndexList) QPersistentModelIndexData *QPersistentModelIndexData::create(const QModelIndex &index) { diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 439e63a362..f86a945c52 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -537,12 +537,8 @@ inline Qt::ItemFlags QModelIndex::flags() const inline size_t qHash(const QModelIndex &index, size_t seed = 0) noexcept { return size_t((size_t(index.row()) << 4) + size_t(index.column()) + index.internalId()) ^ seed; } -Q_CORE_EXPORT int qRegisterNormalizedMetaType_QList_QModelIndex(const QByteArray &name); -template <> inline int qRegisterNormalizedMetaType<QList<QModelIndex>>(const QByteArray &name) -{ return qRegisterNormalizedMetaType_QList_QModelIndex(name); } - QT_END_NAMESPACE -Q_DECLARE_METATYPE(QModelIndexList) +QT_DECL_METATYPE_EXTERN(QModelIndexList, Q_CORE_EXPORT) #endif // QABSTRACTITEMMODEL_H diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index f144bf9357..286a57eb3e 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -50,6 +50,9 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QItemSelectionRange) +QT_IMPL_METATYPE_EXTERN(QItemSelection) + /*! \class QItemSelectionRange \inmodule QtCore diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 1d3fb0ec2a..423d6cc057 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -238,7 +238,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &); QT_END_NAMESPACE -Q_DECLARE_METATYPE(QItemSelectionRange) -Q_DECLARE_METATYPE(QItemSelection) +QT_DECL_METATYPE_EXTERN(QItemSelectionRange, Q_CORE_EXPORT) +QT_DECL_METATYPE_EXTERN(QItemSelection, Q_CORE_EXPORT) #endif // QITEMSELECTIONMODEL_H diff --git a/src/corelib/kernel/qdeadlinetimer.cpp b/src/corelib/kernel/qdeadlinetimer.cpp index 20b2107d55..1aca02f600 100644 --- a/src/corelib/kernel/qdeadlinetimer.cpp +++ b/src/corelib/kernel/qdeadlinetimer.cpp @@ -43,6 +43,8 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QDeadlineTimer) + namespace { class TimeReference { diff --git a/src/corelib/kernel/qdeadlinetimer.h b/src/corelib/kernel/qdeadlinetimer.h index 0720a32b56..32e7d2cde3 100644 --- a/src/corelib/kernel/qdeadlinetimer.h +++ b/src/corelib/kernel/qdeadlinetimer.h @@ -224,6 +224,6 @@ Q_DECLARE_SHARED(QDeadlineTimer) QT_END_NAMESPACE -Q_DECLARE_METATYPE(QDeadlineTimer) +QT_DECL_METATYPE_EXTERN(QDeadlineTimer, Q_CORE_EXPORT) #endif // QDEADLINETIMER_H diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 59b1f23d21..954878f6db 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -97,6 +97,7 @@ QT_BEGIN_NAMESPACE #define NS(x) QT_PREPEND_NAMESPACE(x) +QT_IMPL_METATYPE_EXTERN_TAGGED(QtMetaTypePrivate::QPairVariantInterfaceImpl, QPairVariantInterfaceImpl) namespace { struct DefinedTypesFilter { diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index cff94d3324..62798f4cc8 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -1257,19 +1257,36 @@ int qRegisterNormalizedMetaTypeImplementation(const QT_PREPEND_NAMESPACE(QByteAr // This primary template calls the -Implementation, like all other specialisations should. // But the split allows to // - in a header: -// - declare, but not define, a specialization of this template -// - add an explicit instantiation declaration (extern template ...) +// - define a specialization of this template calling an out-of-line function +// (QT_DECL_METATYPE_EXTERN{,_TAGGED}) // - in the .cpp file: -// - define the specialization to call the -Implementation -// - add an explicit instantiation definition -// This prevents the compiler from taking the leeway for inline functions in -// [temp.explicit]/13 Note 4 +// - define the out-of-line wrapper to call the -Implementation +// (QT_IMPL_METATYPE_EXTERN{,_TAGGED}) +// The _TAGGED variants let you choose a tag (must be a C identifier) to disambiguate +// the out-of-line function; the non-_TAGGED variants use the passed class name as tag. template <typename T> int qRegisterNormalizedMetaType(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName) { return qRegisterNormalizedMetaTypeImplementation<T>(normalizedTypeName); } +#define QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TAG, EXPORT) \ + QT_BEGIN_NAMESPACE \ + EXPORT int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &); \ + template <> inline int qRegisterNormalizedMetaType< TYPE >(const QByteArray &name) \ + { return qRegisterNormalizedMetaType_ ## TAG (name); } \ + QT_END_NAMESPACE \ + Q_DECLARE_METATYPE(TYPE) \ + /* end */ +#define QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TAG) \ + int qRegisterNormalizedMetaType_ ## TAG (const QByteArray &name) \ + { return qRegisterNormalizedMetaTypeImplementation< TYPE >(name); } \ + /* end */ +#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT) \ + QT_DECL_METATYPE_EXTERN_TAGGED(TYPE, TYPE, EXPORT) +#define QT_IMPL_METATYPE_EXTERN(TYPE) \ + QT_IMPL_METATYPE_EXTERN_TAGGED(TYPE, TYPE) + template <typename T> int qRegisterMetaType(const char *typeName) { @@ -2521,6 +2538,7 @@ constexpr const QtPrivate::QMetaTypeInterface *const qt_incomplete_metaTypeArray QT_END_NAMESPACE -Q_DECLARE_METATYPE(QtMetaTypePrivate::QPairVariantInterfaceImpl) +QT_DECL_METATYPE_EXTERN_TAGGED(QtMetaTypePrivate::QPairVariantInterfaceImpl, + QPairVariantInterfaceImpl, Q_CORE_EXPORT) #endif // QMETATYPE_H diff --git a/src/corelib/kernel/qsocketnotifier.cpp b/src/corelib/kernel/qsocketnotifier.cpp index 8d4052b8f9..668eb207db 100644 --- a/src/corelib/kernel/qsocketnotifier.cpp +++ b/src/corelib/kernel/qsocketnotifier.cpp @@ -58,6 +58,9 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(lcSocketNotifierDeprecation) Q_LOGGING_CATEGORY(lcSocketNotifierDeprecation, "qt.core.socketnotifier_deprecation"); +QT_IMPL_METATYPE_EXTERN_TAGGED(QSocketNotifier::Type, QSocketNotifier_Type) +QT_IMPL_METATYPE_EXTERN(QSocketDescriptor) + class QSocketNotifierPrivate : public QObjectPrivate { Q_DECLARE_PUBLIC(QSocketNotifier) diff --git a/src/corelib/kernel/qsocketnotifier.h b/src/corelib/kernel/qsocketnotifier.h index 9c806235fc..2014145d21 100644 --- a/src/corelib/kernel/qsocketnotifier.h +++ b/src/corelib/kernel/qsocketnotifier.h @@ -137,7 +137,8 @@ private: }; QT_END_NAMESPACE -Q_DECLARE_METATYPE(QSocketNotifier::Type) -Q_DECLARE_METATYPE(QSocketDescriptor) + +QT_DECL_METATYPE_EXTERN_TAGGED(QSocketNotifier::Type, QSocketNotifier_Type, Q_CORE_EXPORT) +QT_DECL_METATYPE_EXTERN(QSocketDescriptor, Q_CORE_EXPORT) #endif // QSOCKETNOTIFIER_H diff --git a/src/corelib/serialization/qcborcommon.cpp b/src/corelib/serialization/qcborcommon.cpp index 27ab67d355..b39bb37edb 100644 --- a/src/corelib/serialization/qcborcommon.cpp +++ b/src/corelib/serialization/qcborcommon.cpp @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QCborTag) + #include <cborerrorstrings.c> /*! diff --git a/src/corelib/serialization/qcborcommon.h b/src/corelib/serialization/qcborcommon.h index 2ea0cec44c..b862d1aafb 100644 --- a/src/corelib/serialization/qcborcommon.h +++ b/src/corelib/serialization/qcborcommon.h @@ -151,7 +151,7 @@ enum class QCborNegativeInteger : quint64 {}; QT_END_NAMESPACE -Q_DECLARE_METATYPE(QCborTag) +QT_DECL_METATYPE_EXTERN(QCborTag, Q_CORE_EXPORT) // To avoid changing namespace we need to reinstate defines, even though our .cpp // will then have to remove them again. diff --git a/src/corelib/tools/qversionnumber.cpp b/src/corelib/tools/qversionnumber.cpp index 38977c3db8..1d05fdd89c 100644 --- a/src/corelib/tools/qversionnumber.cpp +++ b/src/corelib/tools/qversionnumber.cpp @@ -57,6 +57,9 @@ QT_BEGIN_NAMESPACE +QT_IMPL_METATYPE_EXTERN(QVersionNumber) +QT_IMPL_METATYPE_EXTERN(QTypeRevision) + /*! \class QVersionNumber \inmodule QtCore diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index 8efdde3391..e72e4efc23 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -494,7 +494,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QTypeRevision &revision); QT_END_NAMESPACE -Q_DECLARE_METATYPE(QVersionNumber) -Q_DECLARE_METATYPE(QTypeRevision) +QT_DECL_METATYPE_EXTERN(QVersionNumber, Q_CORE_EXPORT) +QT_DECL_METATYPE_EXTERN(QTypeRevision, Q_CORE_EXPORT) #endif // QVERSIONNUMBER_H |