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.11791e2a50
andd783363f60
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
|
||||
|
||||
template <typename F> 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<QVariant::PrivateShared, Deleter> ptr;
|
||||
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());
|
||||
return ptr.release();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user