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>
This commit is contained in:
Andrei Golubev 2020-10-12 16:29:27 +02:00
parent 115ead8fe4
commit bfc6e2d69d
4 changed files with 32 additions and 30 deletions

View File

@ -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;
}

View File

@ -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.

View File

@ -403,8 +403,9 @@ void tst_QtConcurrentFilter::filteredReduced()
const int intSum = 6; // sum of even values
const Number numberSum = 6; // sum of even values
void (QList<int>::*pushBackInt)(const int &) = &QList<int>::push_back;
void (QList<Number>::*pushBackNumber)(const Number &) = &QList<Number>::push_back;
void (QList<int>::*pushBackInt)(QList<int>::parameter_type) = &QList<int>::push_back;
void (QList<Number>::*pushBackNumber)(QList<Number>::parameter_type) =
&QList<Number>::push_back;
auto lambdaIsEven = [](const int &x) {
return (x & 1) == 0;
@ -703,8 +704,9 @@ void tst_QtConcurrentFilter::filteredReducedInitialValue()
const int intSum = 16; // sum of even values and initial value
const Number numberSum = 16; // sum of even values and initial value
void (QList<int>::*pushBackInt)(const int &) = &QList<int>::push_back;
void (QList<Number>::*pushBackNumber)(const Number &) = &QList<Number>::push_back;
void (QList<int>::*pushBackInt)(QList<int>::parameter_type) = &QList<int>::push_back;
void (QList<Number>::*pushBackNumber)(QList<Number>::parameter_type) =
&QList<Number>::push_back;
auto lambdaIsEven = [](const int &x) {
return (x & 1) == 0;

View File

@ -718,7 +718,7 @@ void tst_QtConcurrentMap::mappedReduced()
const int sum = 6;
const int sumOfSquares = 14;
void (QList<int>::*push_back)(const int &) = &QList<int>::push_back;
void (QList<int>::*push_back)(QList<int>::parameter_type) = &QList<int>::push_back;
auto lambdaSquare = [](int x) {
return x * x;
@ -1009,7 +1009,7 @@ void tst_QtConcurrentMap::mappedReducedInitialValue()
const int sumOfSquares = 24;
const int intInitial = 10;
void (QList<int>::*push_back)(const int &) = &QList<int>::push_back;
void (QList<int>::*push_back)(QList<int>::parameter_type) = &QList<int>::push_back;
auto lambdaSquare = [](int x) {
return x * x;