QVariant::PrivateShared: move create() and free() into the .cpp

They don't need to be in the header. They're still inline though.

Change-Id: I3859764fed084846bcb0fffd17044f49031feefc
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2022-07-22 17:55:37 -07:00
parent 5ee253e188
commit e2e2412d59
2 changed files with 29 additions and 24 deletions

View File

@ -298,6 +298,33 @@ static QVariant::Private clonePrivate(const QVariant::Private &other)
} // anonymous used to hide QVariant handlers
inline QVariant::PrivateShared *
QVariant::PrivateShared::create(const QtPrivate::QMetaTypeInterface *type)
{
Q_ASSERT(type);
size_t size = type->size;
size_t align = type->alignment;
size += sizeof(PrivateShared);
if (align > sizeof(PrivateShared)) {
// The alignment is larger than the alignment we can guarantee for the pointer
// directly following PrivateShared, so we need to allocate some additional
// memory to be able to fit the object into the available memory with suitable
// alignment.
size += align - sizeof(PrivateShared);
}
void *data = operator new(size);
auto *ps = new (data) QVariant::PrivateShared();
ps->offset = int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps));
return ps;
}
inline void QVariant::PrivateShared::free(PrivateShared *p)
{
p->~PrivateShared();
operator delete(p);
}
inline QVariant::Private::Private(const QtPrivate::QMetaTypeInterface *iface) noexcept
: is_shared(false), is_null(false), packedType(quintptr(iface) >> 2)
{

View File

@ -390,30 +390,8 @@ public:
private:
inline PrivateShared() : ref(1) { }
public:
static PrivateShared *create(const QtPrivate::QMetaTypeInterface *type)
{
Q_ASSERT(type);
size_t size = type->size;
size_t align = type->alignment;
size += sizeof(PrivateShared);
if (align > sizeof(PrivateShared)) {
// The alignment is larger than the alignment we can guarantee for the pointer
// directly following PrivateShared, so we need to allocate some additional
// memory to be able to fit the object into the available memory with suitable
// alignment.
size += align - sizeof(PrivateShared);
}
void *data = operator new(size);
auto *ps = new (data) QVariant::PrivateShared();
ps->offset = int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps));
return ps;
}
static void free(PrivateShared *p)
{
p->~PrivateShared();
operator delete(p);
}
static PrivateShared *create(const QtPrivate::QMetaTypeInterface *type);
static void free(PrivateShared *p);
alignas(8) QAtomicInt ref;
int offset;