From c1f510b3596eaefb54cec83206cccbfecd25fc3b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 7 Dec 2021 17:30:09 +0100 Subject: [PATCH] QVarLengthArray: implement append() via emplace_back() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Less code duplication, means less functions to move into the upcoming QVLABase. Change-Id: I67a817c971a4e5a81ae45ff30282878be1bde2aa Reviewed-by: MÃ¥rten Nordheim --- src/corelib/tools/qvarlengtharray.h | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index ab02846ce1..621949f506 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -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);