diff options
author | Marc Mutz <marc.mutz@qt.io> | 2021-12-07 17:30:09 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2021-12-09 18:49:33 +0100 |
commit | c1f510b3596eaefb54cec83206cccbfecd25fc3b (patch) | |
tree | 41e184849f7302e8e837b780cd76beaf2d19206a | |
parent | 7db44f60b1fde67aea9d3fd48b9e0a66c644bb22 (diff) |
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>
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 17 |
1 files 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); |