summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-10-30 08:45:19 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-04 11:21:27 +0100
commit90fadbb3656eaf5db0aa9341f2ef4b2d44156446 (patch)
tree0f58f389ddf1cb72f7f63ba334eb0fc600b63f3d /src
parentb99271caa6231ad753bc796dae5202ebc1cb9440 (diff)
Remove the prepare call in QArrayData::appendInitialize()
It's causing a performance bottleneck and is not required anymore after changing the allocation strategy. Take the opportunity to change the signature from using size_t to qsizetype. Change-Id: I74ff1637007cf7072de80e7383a23fdfe1ccd986 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qarraydataops.h27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 507f8f153f..ac6e25d364 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -248,12 +248,12 @@ protected:
public:
typedef typename QArrayDataPointer<T>::parameter_type parameter_type;
- void appendInitialize(size_t newSize)
+ void appendInitialize(qsizetype newSize)
{
Q_ASSERT(this->isMutable());
Q_ASSERT(!this->isShared());
- Q_ASSERT(newSize > size_t(this->size));
- Q_ASSERT(newSize - this->size <= size_t(this->freeSpaceAtEnd()));
+ Q_ASSERT(newSize > this->size);
+ Q_ASSERT(newSize - this->size <= this->freeSpaceAtEnd());
::memset(static_cast<void *>(this->end()), 0, (newSize - this->size) * sizeof(T));
this->size = qsizetype(newSize);
@@ -491,17 +491,17 @@ protected:
public:
typedef typename QArrayDataPointer<T>::parameter_type parameter_type;
- void appendInitialize(size_t newSize)
+ void appendInitialize(qsizetype newSize)
{
Q_ASSERT(this->isMutable());
Q_ASSERT(!this->isShared());
- Q_ASSERT(newSize > size_t(this->size));
- Q_ASSERT(newSize - this->size <= size_t(this->freeSpaceAtEnd()));
+ Q_ASSERT(newSize > this->size);
+ Q_ASSERT(newSize - this->size <= this->freeSpaceAtEnd());
T *const b = this->begin();
do {
new (b + this->size) T;
- } while (size_t(++this->size) != newSize);
+ } while (++this->size != newSize);
}
void moveAppend(T *b, T *e)
@@ -1342,19 +1342,12 @@ public:
// using Base::assign;
// using Base::compare;
- void appendInitialize(size_t newSize)
+ void appendInitialize(qsizetype newSize)
{
Q_ASSERT(this->isMutable());
Q_ASSERT(!this->isShared());
- Q_ASSERT(newSize > size_t(this->size));
- Q_ASSERT(newSize <= size_t(this->allocatedCapacity()));
-
- // Since this is mostly an initialization function, do not follow append
- // logic of space arrangement. Instead, only prepare as much free space
- // as needed for this specific operation
- const size_t n = newSize - this->size;
- prepareFreeSpace(GrowsForwardTag{}, n,
- qMin(n, size_t(this->freeSpaceAtBegin()))); // ### perf. loss
+ Q_ASSERT(newSize > this->size);
+ Q_ASSERT(newSize - this->size <= this->freeSpaceAtEnd());
Base::appendInitialize(newSize);
}