summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydataops.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2020-11-10 11:20:41 +0100
committerLars Knoll <lars.knoll@qt.io>2020-11-17 11:46:52 +0100
commit07c7cbf1a0b491125cf91570a870725b35e4cb71 (patch)
treeeb690c69929a45cb7a385c4d49536cf846e43419 /src/corelib/tools/qarraydataops.h
parent590d4b3443ee94425e4513ab20a40823ec5ed4e4 (diff)
Don't implement copyAppend() through insert()
We've been expanding to a lot more code than we need to, and the code was slower than it needed to. Change-Id: I79e49fefd8b3fedb26a32a8d4c80e71b2c0c4041 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydataops.h')
-rw-r--r--src/corelib/tools/qarraydataops.h75
1 files changed, 52 insertions, 23 deletions
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index e2ff3f676b3..e0f3484bcb4 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -242,7 +242,7 @@ public:
this->size = qsizetype(newSize);
}
- void moveAppend(T *b, T *e) noexcept
+ void copyAppend(const T *b, const T *e) noexcept
{
Q_ASSERT(this->isMutable() || b == e);
Q_ASSERT(!this->isShared() || b == e);
@@ -256,6 +256,24 @@ public:
this->size += (e - b);
}
+ void copyAppend(qsizetype n, parameter_type t) noexcept
+ {
+ Q_ASSERT(!this->isShared() || n == 0);
+ Q_ASSERT(this->freeSpaceAtEnd() >= n);
+ if (!n)
+ return;
+
+ T *where = this->end();
+ this->size += qsizetype(n);
+ while (n--)
+ *where++ = t;
+ }
+
+ void moveAppend(T *b, T *e) noexcept
+ {
+ copyAppend(b, e);
+ }
+
void truncate(size_t newSize) noexcept
{
Q_ASSERT(this->isMutable());
@@ -484,6 +502,38 @@ public:
} while (++this->size != newSize);
}
+ void copyAppend(const T *b, const T *e)
+ {
+ Q_ASSERT(this->isMutable() || b == e);
+ Q_ASSERT(!this->isShared() || b == e);
+ Q_ASSERT(b <= e);
+ Q_ASSERT((e - b) <= this->freeSpaceAtEnd());
+
+ if (b == e) // short-cut and handling the case b and e == nullptr
+ return;
+
+ T *data = this->begin();
+ while (b < e) {
+ new (data + this->size) T(*b);
+ ++b;
+ ++this->size;
+ }
+ }
+
+ void copyAppend(qsizetype n, parameter_type t)
+ {
+ Q_ASSERT(!this->isShared() || n == 0);
+ Q_ASSERT(this->freeSpaceAtEnd() >= n);
+ if (!n)
+ return;
+
+ T *data = this->begin();
+ while (n--) {
+ new (data + this->size) T(t);
+ ++this->size;
+ }
+ }
+
void moveAppend(T *b, T *e)
{
Q_ASSERT(this->isMutable() || b == e);
@@ -1108,18 +1158,7 @@ public:
// using Base::assign;
// using Base::compare;
- void copyAppend(const T *b, const T *e)
- {
- Q_ASSERT(this->isMutable() || b == e);
- Q_ASSERT(!this->isShared() || b == e);
- Q_ASSERT(b <= e);
- Q_ASSERT((e - b) <= this->freeSpaceAtEnd());
-
- if (b == e) // short-cut and handling the case b and e == nullptr
- return;
-
- Base::insert(GrowsForwardTag{}, this->end(), b, e);
- }
+ using Base::copyAppend;
template<typename It>
void copyAppend(It b, It e, QtPrivate::IfIsForwardIterator<It> = true,
@@ -1139,16 +1178,6 @@ public:
}
}
- void copyAppend(size_t n, parameter_type t)
- {
- Q_ASSERT(!this->isShared() || n == 0);
- Q_ASSERT(size_t(this->allocatedCapacity() - this->size) >= n);
- if (!n)
- return;
-
- Base::insert(GrowsForwardTag{}, this->end(), n, t);
- }
-
public:
void insert(qsizetype i, qsizetype n, parameter_type t)
{