QVarLengthArray: implement append() via emplace_back()

Less code duplication, means less functions to move into the
upcoming QVLABase.

Change-Id: I67a817c971a4e5a81ae45ff30282878be1bde2aa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Marc Mutz 2021-12-07 17:30:09 +01:00
parent 7db44f60b1
commit c1f510b359
1 changed files with 5 additions and 12 deletions

View File

@ -225,22 +225,15 @@ public:
inline void append(const T &t)
{
if (size() == capacity()) { // i.e. size() != 0
T copy(t);
reallocate(size(), size() << 1);
new (end()) T(std::move(copy));
} else {
new (end()) T(t);
}
++s;
if (size() == capacity())
emplace_back(T(t));
else
emplace_back(t);
}
void append(T &&t)
{
if (size() == capacity())
reallocate(size(), size() << 1);
new (end()) T(std::move(t));
++s;
emplace_back(std::move(t));
}
void append(const T *buf, qsizetype size);