QVariant: Extract Method PrivateShared::computeAllocationSize()
Will be re-used in the upcoming emplace() function. Task-number: QTBUG-112187 Change-Id: Ie2b4570b7ba6c9d0ce938203933758a0d0d59f5a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
3a7ddd7274
commit
4e860a66d6
@ -78,6 +78,7 @@ public:
|
||||
private:
|
||||
inline PrivateShared() : ref(1) { }
|
||||
public:
|
||||
static size_t computeAllocationSize(size_t size, size_t align);
|
||||
static PrivateShared *create(size_t size, size_t align);
|
||||
static void free(PrivateShared *p);
|
||||
|
||||
|
@ -34,7 +34,7 @@ customConstructShared(size_t size, size_t align, F &&construct)
|
||||
return ptr.release();
|
||||
}
|
||||
|
||||
inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, size_t align)
|
||||
inline size_t QVariant::PrivateShared::computeAllocationSize(size_t size, size_t align)
|
||||
{
|
||||
size += sizeof(PrivateShared);
|
||||
if (align > sizeof(PrivateShared)) {
|
||||
@ -44,6 +44,12 @@ inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, siz
|
||||
// alignment.
|
||||
size += align - sizeof(PrivateShared);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, size_t align)
|
||||
{
|
||||
size = computeAllocationSize(size, align);
|
||||
void *data = operator new(size);
|
||||
auto *ps = new (data) QVariant::PrivateShared();
|
||||
ps->offset = int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps));
|
||||
|
Loading…
Reference in New Issue
Block a user