diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-10-22 12:36:06 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-10-29 17:31:57 +0200 |
commit | 77b99e8111cdd06b4fe12f2e18950a1e40ee2b76 (patch) | |
tree | 579903f0389609a4a4a5df8ecc788ab4dd73485f /src/corelib/kernel | |
parent | bbfd625b6351f0a28fd1f2894ed92b8da6d97c97 (diff) |
QMetaType: Avoid superfluous template instantiations
Apparently msvc still parses the template and generates code for it when
it encounters an extern template declaration. Thus, instead of speeding
up compilation, it gets slowed down significantly as the instantiation
would happen in every compilation unit that (transitively) included
qmetatype.h.
Task-number: QTBUG-97601
Change-Id: Id5e934afb14ad8973df1b9197aef336b22220111
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r-- | src/corelib/kernel/qmetatype.cpp | 11 | ||||
-rw-r--r-- | src/corelib/kernel/qmetatype.h | 8 |
2 files changed, 8 insertions, 11 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 3758d3c941..ba301ca522 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -2974,24 +2974,17 @@ static const QtPrivate::QMetaTypeInterface *interfaceForType(int typeId) QMetaType::QMetaType(int typeId) : QMetaType(interfaceForType(typeId)) {} namespace QtPrivate { -#ifndef QT_BOOTSTRAPPED - -#if defined(Q_CC_MSVC) && defined(QT_BUILD_CORE_LIB) -#define QT_METATYPE_TEMPLATE_EXPORT Q_CORE_EXPORT -#else -#define QT_METATYPE_TEMPLATE_EXPORT -#endif +#if !defined(QT_BOOTSTRAPPED) && !defined(Q_CC_MSVC) // Explicit instantiation definition #define QT_METATYPE_DECLARE_TEMPLATE_ITER(TypeName, Id, Name) \ - template class QT_METATYPE_TEMPLATE_EXPORT QMetaTypeForType<Name>; + template class QMetaTypeForType<Name>; QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(QT_METATYPE_DECLARE_TEMPLATE_ITER) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER) QT_FOR_EACH_STATIC_CORE_CLASS(QT_METATYPE_DECLARE_TEMPLATE_ITER) QT_FOR_EACH_STATIC_CORE_POINTER(QT_METATYPE_DECLARE_TEMPLATE_ITER) QT_FOR_EACH_STATIC_CORE_TEMPLATE(QT_METATYPE_DECLARE_TEMPLATE_ITER) #undef QT_METATYPE_DECLARE_TEMPLATE_ITER -#undef QT_METATYPE_TEMPLATE_EXPORT #endif } diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index 346ae3667a..669273af68 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -2369,9 +2369,13 @@ public: }; #undef QT_METATYPE_CONSTEXPRLAMDA -#ifndef QT_BOOTSTRAPPED +/* + MSVC instantiates extern templates +(https://developercommunity.visualstudio.com/t/c11-extern-templates-doesnt-work-for-class-templat/157868) + */ +#if !defined(QT_BOOTSTRAPPED) && !defined(Q_CC_MSVC) -#if !defined(Q_CC_MSVC) || !defined(QT_BUILD_CORE_LIB) +#if !defined(QT_BUILD_CORE_LIB) #define QT_METATYPE_TEMPLATE_EXPORT Q_CORE_EXPORT #else #define QT_METATYPE_TEMPLATE_EXPORT |