summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qstack.h
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2021-11-12 16:31:06 +0100
committerAndrei Golubev <andrei.golubev@qt.io>2021-11-12 22:25:35 +0100
commit2a2fb306b8cfc3f386cf9432c4a343c213ee46f7 (patch)
treecc629b80359e71632740f1ec6ad9e740b546e614 /src/corelib/tools/qstack.h
parent3446313c7a5cd6005089866a7b20c9f28e132a0a (diff)
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>
Diffstat (limited to 'src/corelib/tools/qstack.h')
-rw-r--r--src/corelib/tools/qstack.h23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h
index a0e39f8ece..c43c63cdd2 100644
--- a/src/corelib/tools/qstack.h
+++ b/src/corelib/tools/qstack.h
@@ -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