diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-10-12 16:29:27 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-10-22 20:47:10 +0200 |
commit | bfc6e2d69d2514f7b4e889d08475972eb2f340a6 (patch) | |
tree | 0251582adcc3d5bf7be22213080e6065a09ec151 /src/corelib | |
parent | 115ead8fe463606aafc82641425423337053af2b (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qlist.h | 26 | ||||
-rw-r--r-- | src/corelib/tools/qlist.qdoc | 22 |
2 files changed, 24 insertions, 24 deletions
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<T> &l) { append(l.constBegin(), l.constEnd()); } void append(QList<T> &&l); void prepend(rvalue_ref t); - void prepend(const T &t); + void prepend(parameter_type t); template <typename ...Args> reference emplaceBack(Args&&... args) { return *emplace(count(), std::forward<Args>(args)...); } @@ -301,7 +301,7 @@ public: iterator insert( const_iterator pos, InputIt first, InputIt last ); iterator insert( const_iterator pos, std::initializer_list<T> 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<T>::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<T> mid(qsizetype pos, qsizetype len = -1) const; QList<T> 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<T> operator+(QList<T> &&l) const { QList n = *this; n += std::move(l); return n; } - inline QList<T> &operator+=(const T &t) + inline QList<T> &operator+=(parameter_type t) { append(t); return *this; } - inline QList<T> &operator<< (const T &t) + inline QList<T> &operator<< (parameter_type t) { append(t); return *this; } inline QList<T> &operator<<(const QList<T> &l) { *this += l; return *this; } @@ -593,14 +593,14 @@ inline void QList<T>::remove(qsizetype i, qsizetype n) } template <typename T> -inline void QList<T>::prepend(const T &t) +inline void QList<T>::prepend(parameter_type t) { insert(0, 1, t); } template <typename T> void QList<T>::prepend(rvalue_ref t) { insert(0, std::move(t)); } template<typename T> -inline T QList<T>::value(qsizetype i, const T &defaultValue) const +inline T QList<T>::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 <typename T> QList<T>::QList(qsizetype size, const T &value) +/*! \fn template <typename T> QList<T>::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 <typename T> void QList<T>::prepend(const T &value) + \fn template <typename T> void QList<T>::prepend(parameter_type value) \fn template <typename T> void QList<T>::prepend(rvalue_ref value) Inserts \a value at the beginning of the list. @@ -793,7 +793,7 @@ */ -/*! \fn template <typename T> void QList<T>::replace(qsizetype i, const T &value) +/*! \fn template <typename T> void QList<T>::replace(qsizetype i, parameter_type value) \fn template <typename T> void QList<T>::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 <typename T> bool QList<T>::startsWith(const T &value) const +/*! \fn template <typename T> bool QList<T>::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 <typename T> bool QList<T>::endsWith(const T &value) const +/*! \fn template <typename T> bool QList<T>::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 <typename T> qsizetype QList<T>::count(const T &value) const +/*! \fn template <typename T> qsizetype QList<T>::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 <typename T> T QList<T>::value(qsizetype i, const T &defaultValue) const +/*! \fn template <typename T> T QList<T>::value(qsizetype i, parameter_type defaultValue) const \overload If the index \a i is out of bounds, the function returns \a defaultValue. */ -/*! \fn template <typename T> void QList<T>::push_back(const T &value) +/*! \fn template <typename T> void QList<T>::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 <typename T> void QList<T>::push_front(const T &value) + \fn template <typename T> void QList<T>::push_front(parameter_type value) \fn template <typename T> void QList<T>::push_front(rvalue_ref value) This function is provided for STL compatibility. It is equivalent @@ -1326,7 +1326,7 @@ \sa operator+(), append() */ -/*! \fn template <typename T> void QList<T>::operator+=(const T &value) +/*! \fn template <typename T> void QList<T>::operator+=(parameter_type value) \overload @@ -1359,7 +1359,7 @@ \sa operator+=() */ -/*! \fn template <typename T> QList<T> &QList<T>::operator<<(const T &value) +/*! \fn template <typename T> QList<T> &QList<T>::operator<<(parameter_type value) Appends \a value to the list and returns a reference to this list. |