QStack: simplify the class (even more)
Most methods just do the same thing that is implemented in QList, so just use QList methods The QStack::pop() implementation should no longer go through the resize which is likely slower, expands to more-code (unless optimized away neatly) than erasure of single element through QList API (which we optimized at some point to be fast) It is also meaningless (afair) to have `inline` keyword when a method is both declared and defined within the class' body, so we can drop that as well Change-Id: If9de3429be7418ed0ae13c571e28556a358eab05 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
3446313c7a
commit
2a2fb306b8
@ -49,26 +49,13 @@ class QStack : public QList<T>
|
||||
{
|
||||
public:
|
||||
// compiler-generated special member functions are fine!
|
||||
inline void swap(QStack<T> &other) noexcept { QList<T>::swap(other); } // prevent QList<->QStack swaps
|
||||
inline void push(const T &t) { QList<T>::append(t); }
|
||||
T pop();
|
||||
T &top();
|
||||
const T &top() const;
|
||||
void swap(QStack<T> &other) noexcept { QList<T>::swap(other); } // prevent QList<->QStack swaps
|
||||
void push(const T &t) { QList<T>::append(t); }
|
||||
T pop() { return QList<T>::takeLast(); }
|
||||
T &top() { return QList<T>::last(); }
|
||||
const T &top() const { return QList<T>::last(); }
|
||||
};
|
||||
|
||||
template<class T>
|
||||
inline T QStack<T>::pop()
|
||||
{ Q_ASSERT(!this->isEmpty()); T t = this->data()[this->size() -1];
|
||||
this->resize(this->size()-1); return t; }
|
||||
|
||||
template<class T>
|
||||
inline T &QStack<T>::top()
|
||||
{ Q_ASSERT(!this->isEmpty()); this->detach(); return this->data()[this->size()-1]; }
|
||||
|
||||
template<class T>
|
||||
inline const T &QStack<T>::top() const
|
||||
{ Q_ASSERT(!this->isEmpty()); return this->data()[this->size()-1]; }
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QSTACK_H
|
||||
|
Loading…
Reference in New Issue
Block a user