From 0ecf8a21587e33c5c5b554d5bc059488001c8990 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 31 May 2023 19:33:10 +0200 Subject: [PATCH] =?UTF-8?q?QVariant:=20make=20customConstructShared()=20SC?= =?UTF-8?q?ARY=C2=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract Method non-template customConstructSharedImpl() to avoid instantiating std::unique_ptr with a different per-F Deleter over and over again. Not picking to 6.5 because the function was confined to the qvariant.cpp TU in those versions. Cf. 11791e2a50417661679f84aeae21ce959cab638f and d783363f60173f1bc6525f1a8bbbd87f1e3afc1d for similar issues. ยน https://www.open-std.org/jtc1/sc22/WG21/docs/papers/2009/n2911.pdf Pick-to: 6.6 Change-Id: I73d21d929a7db2ab47f62a3246cf913d82e3db75 Reviewed-by: Fabian Kosmale Reviewed-by: Thiago Macieira --- src/corelib/kernel/qvariant_p.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index fef43dab03..d2a7390938 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -19,8 +19,7 @@ QT_BEGIN_NAMESPACE -template static QVariant::PrivateShared * -customConstructShared(size_t size, size_t align, F &&construct) +inline auto customConstructSharedImpl(size_t size, size_t align) { struct Deleter { void operator()(QVariant::PrivateShared *p) const @@ -30,6 +29,13 @@ customConstructShared(size_t size, size_t align, F &&construct) // this is exception-safe std::unique_ptr ptr; ptr.reset(QVariant::PrivateShared::create(size, align)); + return ptr; +} + +template static QVariant::PrivateShared * +customConstructShared(size_t size, size_t align, F &&construct) +{ + auto ptr = customConstructSharedImpl(size, align); construct(ptr->data()); return ptr.release(); }