diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-07-13 12:26:36 +0300 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-08-18 12:55:38 +0200 |
commit | 4bf8e82d413815cd8ef076e7a5c65d0651a0e27a (patch) | |
tree | 184ab55f4a166fe64e1a7002b9601c18dc9f09de /src/corelib/tools/qarraydata.h | |
parent | 0bd647fa4ffb3319bf3b1d044441b137910629e1 (diff) |
Add QArrayDataPointer::freeSpace*() functions
Added functions that tell how much free space is available at the
beginning and at the end of the storage
Updated preconditions of operations to use freeSpace* functions
Also, changed casts uint(this->size) to size_t(this->size)
Task-number: QTBUG-84320
Change-Id: Iad94c1060a00f62068da9d1327e332a00d4f4109
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 0226fa4c92..856a9521ad 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2019 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -235,6 +235,15 @@ struct QTypedArrayData static_assert(sizeof(QTypedArrayData) == sizeof(QArrayData)); QArrayData::deallocate(data, sizeof(T), alignof(AlignmentDummy)); } + + static T *dataStart(QArrayData *data, qsizetype alignment) noexcept + { + // Alignment is a power of two + Q_ASSERT(alignment >= qsizetype(alignof(QArrayData)) && !(alignment & (alignment - 1))); + void *start = reinterpret_cast<void *>( + (quintptr(data) + sizeof(QArrayData) + alignment - 1) & ~(alignment - 1)); + return static_cast<T *>(start); + } }; namespace QtPrivate { |