QVariant: make customConstructShared() SCARY¹
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 <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
93fe8cb305
commit
0ecf8a2158
@ -19,8 +19,7 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
template <typename F> static QVariant::PrivateShared *
|
inline auto customConstructSharedImpl(size_t size, size_t align)
|
||||||
customConstructShared(size_t size, size_t align, F &&construct)
|
|
||||||
{
|
{
|
||||||
struct Deleter {
|
struct Deleter {
|
||||||
void operator()(QVariant::PrivateShared *p) const
|
void operator()(QVariant::PrivateShared *p) const
|
||||||
@ -30,6 +29,13 @@ customConstructShared(size_t size, size_t align, F &&construct)
|
|||||||
// this is exception-safe
|
// this is exception-safe
|
||||||
std::unique_ptr<QVariant::PrivateShared, Deleter> ptr;
|
std::unique_ptr<QVariant::PrivateShared, Deleter> ptr;
|
||||||
ptr.reset(QVariant::PrivateShared::create(size, align));
|
ptr.reset(QVariant::PrivateShared::create(size, align));
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename F> static QVariant::PrivateShared *
|
||||||
|
customConstructShared(size_t size, size_t align, F &&construct)
|
||||||
|
{
|
||||||
|
auto ptr = customConstructSharedImpl(size, align);
|
||||||
construct(ptr->data());
|
construct(ptr->data());
|
||||||
return ptr.release();
|
return ptr.release();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user