summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydatapointer.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-08-22 15:40:42 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-10-25 12:01:58 -0700
commit2fd0996324304c4c055059a980b6f9b32b843574 (patch)
treedd89257e84270e3d080694c7821892d2522f4f3a /src/corelib/tools/qarraydatapointer.h
parent793cfec9418c6a900883c65e947993f320f5c987 (diff)
QArrayDataPointer: add an allocating constructor
It's by far the most common use, so having to call two things is just cumbersome. Change-Id: I79e700614d034281bf55fffd178f454c4e31929e Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r--src/corelib/tools/qarraydatapointer.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h
index a77db21c99b..201f3e665dd 100644
--- a/src/corelib/tools/qarraydatapointer.h
+++ b/src/corelib/tools/qarraydatapointer.h
@@ -52,6 +52,13 @@ public:
{
}
+ Q_NODISCARD_CTOR explicit
+ QArrayDataPointer(qsizetype alloc, qsizetype n = 0,
+ QArrayData::AllocationOption option = QArrayData::KeepSize)
+ : QArrayDataPointer(Data::allocate(alloc, option), n)
+ {
+ }
+
Q_NODISCARD_CTOR
static QArrayDataPointer fromRawData(const T *rawData, qsizetype length) noexcept
{
@@ -326,11 +333,11 @@ public:
if constexpr (IsFwdIt) {
const qsizetype n = std::distance(first, last);
if (needsDetach() || n > constAllocatedCapacity()) {
- QArrayDataPointer allocated(Data::allocate(detachCapacity(n)));
+ QArrayDataPointer allocated(detachCapacity(n));
swap(allocated);
}
} else if (needsDetach()) {
- QArrayDataPointer allocated(Data::allocate(allocatedCapacity()));
+ QArrayDataPointer allocated(allocatedCapacity());
swap(allocated);
// We don't want to copy data that we know we'll overwrite
}