From bfc6e2d69d2514f7b4e889d08475972eb2f340a6 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Mon, 12 Oct 2020 16:29:27 +0200 Subject: Use parameter_type in QList methods QList::parameter_type is defined and used to give better performance e.g. for arithmetic types. Let's use it consistently in QList API instead of const T & Change-Id: I2e12bd83f55679b55a14fbb23ab6172a9cf7bbcc Reviewed-by: Thiago Macieira --- src/corelib/tools/qlist.h | 26 +++++++++++++------------- src/corelib/tools/qlist.qdoc | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index fe16bd6e94..6931bd6cbc 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -143,7 +143,7 @@ public: if (size) d->appendInitialize(size); } - QList(qsizetype size, const T &t) + QList(qsizetype size, parameter_type t) : d(Data::allocate(size)) { if (size) @@ -262,7 +262,7 @@ public: void append(const QList &l) { append(l.constBegin(), l.constEnd()); } void append(QList &&l); void prepend(rvalue_ref t); - void prepend(const T &t); + void prepend(parameter_type t); template reference emplaceBack(Args&&... args) { return *emplace(count(), std::forward(args)...); } @@ -301,7 +301,7 @@ public: iterator insert( const_iterator pos, InputIt first, InputIt last ); iterator insert( const_iterator pos, std::initializer_list ilist ); #endif - void replace(qsizetype i, const T &t) + void replace(qsizetype i, parameter_type t) { Q_ASSERT_X(i >= 0 && i < d->size, "QList::replace", "index out of range"); const T copy(t); @@ -332,7 +332,7 @@ public: bool contains(const T &t) const noexcept; #endif - qsizetype count(const T &t) const noexcept + qsizetype count(parameter_type t) const noexcept { return qsizetype(std::count(&*cbegin(), &*cend(), t)); } @@ -411,8 +411,8 @@ public: 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 bool startsWith(const T &t) const { return !isEmpty() && first() == t; } - inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } + 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; QList first(qsizetype n) const @@ -439,7 +439,7 @@ public: } T value(qsizetype i) const { return value(i, T()); } - T value(qsizetype i, const T &defaultValue) const; + T value(qsizetype i, parameter_type defaultValue) const; void swapItemsAt(qsizetype i, qsizetype j) { Q_ASSERT_X(i >= 0 && i < size() && j >= 0 && j < size(), @@ -449,10 +449,10 @@ public: } // STL compatibility - inline void push_back(const T &t) { append(t); } + inline void push_back(parameter_type t) { append(t); } void push_back(rvalue_ref t) { append(std::move(t)); } void push_front(rvalue_ref t) { prepend(std::move(t)); } - inline void push_front(const T &t) { prepend(t); } + inline void push_front(parameter_type t) { prepend(t); } void pop_back() { removeLast(); } void pop_front() { removeFirst(); } @@ -474,9 +474,9 @@ public: { QList n = *this; n += l; return n; } inline QList operator+(QList &&l) const { QList n = *this; n += std::move(l); return n; } - inline QList &operator+=(const T &t) + inline QList &operator+=(parameter_type t) { append(t); return *this; } - inline QList &operator<< (const T &t) + inline QList &operator<< (parameter_type t) { append(t); return *this; } inline QList &operator<<(const QList &l) { *this += l; return *this; } @@ -593,14 +593,14 @@ inline void QList::remove(qsizetype i, qsizetype n) } template -inline void QList::prepend(const T &t) +inline void QList::prepend(parameter_type t) { insert(0, 1, t); } template void QList::prepend(rvalue_ref t) { insert(0, std::move(t)); } template -inline T QList::value(qsizetype i, const T &defaultValue) const +inline T QList::value(qsizetype i, parameter_type defaultValue) const { return size_t(i) < size_t(d->size) ? at(i) : defaultValue; } diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 4a36897ae2..52ac5360c8 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -279,7 +279,7 @@ \sa resize() */ -/*! \fn template QList::QList(qsizetype size, const T &value) +/*! \fn template QList::QList(qsizetype size, parameter_type value) Constructs a list with an initial size of \a size elements. Each element is initialized with \a value. @@ -686,7 +686,7 @@ */ /*! - \fn template void QList::prepend(const T &value) + \fn template void QList::prepend(parameter_type value) \fn template void QList::prepend(rvalue_ref value) Inserts \a value at the beginning of the list. @@ -793,7 +793,7 @@ */ -/*! \fn template void QList::replace(qsizetype i, const T &value) +/*! \fn template void QList::replace(qsizetype i, parameter_type value) \fn template void QList::replace(qsizetype i, rvalue_ref value) Replaces the item at index position \a i with \a value. @@ -994,7 +994,7 @@ \sa indexOf(), count() */ -/*! \fn template bool QList::startsWith(const T &value) const +/*! \fn template bool QList::startsWith(parameter_type value) const \since 4.5 Returns \c true if this list is not empty and its first @@ -1003,7 +1003,7 @@ \sa isEmpty(), first() */ -/*! \fn template bool QList::endsWith(const T &value) const +/*! \fn template bool QList::endsWith(parameter_type value) const \since 4.5 Returns \c true if this list is not empty and its last @@ -1013,7 +1013,7 @@ */ -/*! \fn template qsizetype QList::count(const T &value) const +/*! \fn template qsizetype QList::count(parameter_type value) const Returns the number of occurrences of \a value in the list. @@ -1236,14 +1236,14 @@ \sa at(), operator[]() */ -/*! \fn template T QList::value(qsizetype i, const T &defaultValue) const +/*! \fn template T QList::value(qsizetype i, parameter_type defaultValue) const \overload If the index \a i is out of bounds, the function returns \a defaultValue. */ -/*! \fn template void QList::push_back(const T &value) +/*! \fn template void QList::push_back(parameter_type value) This function is provided for STL compatibility. It is equivalent to append(\a value). @@ -1255,7 +1255,7 @@ */ /*! - \fn template void QList::push_front(const T &value) + \fn template void QList::push_front(parameter_type value) \fn template void QList::push_front(rvalue_ref value) This function is provided for STL compatibility. It is equivalent @@ -1326,7 +1326,7 @@ \sa operator+(), append() */ -/*! \fn template void QList::operator+=(const T &value) +/*! \fn template void QList::operator+=(parameter_type value) \overload @@ -1359,7 +1359,7 @@ \sa operator+=() */ -/*! \fn template QList &QList::operator<<(const T &value) +/*! \fn template QList &QList::operator<<(parameter_type value) Appends \a value to the list and returns a reference to this list. -- cgit v1.2.3