From d783363f60173f1bc6525f1a8bbbd87f1e3afc1d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 8 Nov 2022 10:53:11 +0100 Subject: [PATCH] QFlatMap: make nested mock_object SCARY Swap the definition of the nested mock_object out of the QFlatMap body into a namespace scope and replace it with a template alias. This way, there's _one_ mock_object for every U, not one for every QFlatMap::mock_object ("SCARY"). Should reduce compile times, but I didn't measure. Change-Id: I37f7413a49d0424e06ef4e78d65dea5962599e79 Reviewed-by: Fabian Kosmale --- src/corelib/tools/qflatmap_p.h | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h index ba02503d2b..6937d21544 100644 --- a/src/corelib/tools/qflatmap_p.h +++ b/src/corelib/tools/qflatmap_p.h @@ -83,6 +83,24 @@ public: } }; +namespace detail { +template +class QFlatMapMockPointer +{ + T ref; +public: + QFlatMapMockPointer(T r) + : ref(r) + { + } + + T *operator->() + { + return &ref; + } +}; +} // namespace detail + template, class KeyContainer = QList, class MappedContainer = QList> class QFlatMap : private QFlatMapValueCompare @@ -90,21 +108,7 @@ class QFlatMap : private QFlatMapValueCompare static_assert(std::is_nothrow_destructible_v, "Types with throwing destructors are not supported in Qt containers."); template - class mock_pointer - { - U ref; - public: - mock_pointer(U r) - : ref(r) - { - } - - U *operator->() - { - return &ref; - } - }; - + using mock_pointer = detail::QFlatMapMockPointer; public: using key_type = Key; using mapped_type = T;