QVariant: Extract Method PrivateShared::computeOffset()
Will be re-used in the upcoming emplace() function. No attempt is made to re-write the expression to be more readable. That's left for another commit. Task-number: QTBUG-112187 Change-Id: Id391b78f1477c5225beda8a32c4f6c1393dd51bb Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
585dd9d8d5
commit
1e0e16b5f3
@ -78,6 +78,7 @@ public:
|
||||
private:
|
||||
inline PrivateShared() : ref(1) { }
|
||||
public:
|
||||
static int computeOffset(PrivateShared *ps, size_t align);
|
||||
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,6 +34,11 @@ customConstructShared(size_t size, size_t align, F &&construct)
|
||||
return ptr.release();
|
||||
}
|
||||
|
||||
inline int QVariant::PrivateShared::computeOffset(PrivateShared *ps, size_t align)
|
||||
{
|
||||
return int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps));
|
||||
}
|
||||
|
||||
inline size_t QVariant::PrivateShared::computeAllocationSize(size_t size, size_t align)
|
||||
{
|
||||
size += sizeof(PrivateShared);
|
||||
@ -52,7 +57,7 @@ inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, siz
|
||||
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));
|
||||
ps->offset = computeOffset(ps, align);
|
||||
return ps;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user