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>
This commit is contained in:
Lars Knoll 2020-11-10 11:20:41 +01:00
parent 590d4b3443
commit 07c7cbf1a0

View File

@ -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)
{