From 21bce8925725bfea1abc371301e943d8970c71fc Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 11 Nov 2020 15:50:37 +0100 Subject: Add a couple of noexcept to methods that can't throw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trivial methods that don't modify any data for the most part. Also mark removeFirst/Last() as noexcept. Those methods can't throw exceptions as we require ~T() to be noexcept. Change-Id: I8698705c6113909aa8f7ae021a932df48a224d5d Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Andrei Golubev Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/corelib/tools/qlist.h') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index eefe7b448f..a2cbfb0f36 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -403,8 +403,8 @@ public: } void remove(qsizetype i, qsizetype n = 1); - void removeFirst(); - void removeLast(); + void removeFirst() noexcept; + void removeLast() noexcept; value_type takeFirst() { Q_ASSERT(!isEmpty()); value_type v = std::move(first()); d->eraseFirst(); return v; } value_type takeLast() { Q_ASSERT(!isEmpty()); value_type v = std::move(last()); d->eraseLast(); return v; } @@ -497,11 +497,11 @@ public: // more Qt inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } - inline const T &first() const { Q_ASSERT(!isEmpty()); return *begin(); } - inline const T &constFirst() const { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T &first() const noexcept { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T &constFirst() const noexcept { Q_ASSERT(!isEmpty()); return *begin(); } inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); } - inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } - inline const T &constLast() const { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline const T &last() const noexcept { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline const T &constLast() const noexcept { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(parameter_type t) const { return !isEmpty() && first() == t; } inline bool endsWith(parameter_type t) const { return !isEmpty() && last() == t; } QList mid(qsizetype pos, qsizetype len = -1) const; @@ -544,18 +544,18 @@ public: void push_back(rvalue_ref t) { append(std::move(t)); } void push_front(rvalue_ref t) { prepend(std::move(t)); } inline void push_front(parameter_type t) { prepend(t); } - void pop_back() { removeLast(); } - void pop_front() { removeFirst(); } + void pop_back() noexcept { removeLast(); } + void pop_front() noexcept { removeFirst(); } template reference emplace_back(Args&&... args) { return emplaceBack(std::forward(args)...); } - inline bool empty() const + inline bool empty() const noexcept { return d->size == 0; } inline reference front() { return first(); } - inline const_reference front() const { return first(); } + inline const_reference front() const noexcept { return first(); } inline reference back() { return last(); } - inline const_reference back() const { return last(); } + inline const_reference back() const noexcept { return last(); } void shrink_to_fit() { squeeze(); } // comfort @@ -579,14 +579,14 @@ public: { append(std::move(t)); return *this; } // Consider deprecating in 6.4 or later - static QList fromList(const QList &list) { return list; } - QList toList() const { return *this; } + static QList fromList(const QList &list) noexcept { return list; } + QList toList() const noexcept { return *this; } - static inline QList fromVector(const QList &vector) { return vector; } - inline QList toVector() const { return *this; } + static inline QList fromVector(const QList &vector) noexcept { return vector; } + inline QList toVector() const noexcept { return *this; } template - static QList fromReadOnlyData(const T (&t)[N]) + static QList fromReadOnlyData(const T (&t)[N]) noexcept { return QList({ nullptr, const_cast(t), N }); } @@ -665,7 +665,7 @@ inline void QList::remove(qsizetype i, qsizetype n) } template -inline void QList::removeFirst() +inline void QList::removeFirst() noexcept { Q_ASSERT(!isEmpty()); d.detach(); @@ -673,7 +673,7 @@ inline void QList::removeFirst() } template -inline void QList::removeLast() +inline void QList::removeLast() noexcept { Q_ASSERT(!isEmpty()); d.detach(); -- cgit v1.2.3