summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvector.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r--src/corelib/tools/qvector.h29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 94f3008274..a06fb7b4eb 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -56,8 +56,6 @@
#include <initializer_list>
#endif
-QT_BEGIN_HEADER
-
QT_BEGIN_NAMESPACE
class QRegion;
@@ -140,6 +138,10 @@ public:
void replace(int i, const T &t);
void remove(int i);
void remove(int i, int n);
+ inline void removeFirst() { Q_ASSERT(!isEmpty()); erase(d->begin()); }
+ inline void removeLast();
+ inline T takeFirst() { Q_ASSERT(!isEmpty()); T r = first(); removeFirst(); return r; }
+ inline T takeLast() { Q_ASSERT(!isEmpty()); T r = last(); removeLast(); return r; }
QVector<T> &fill(const T &t, int size = -1);
@@ -200,8 +202,8 @@ public:
typedef int size_type;
inline void push_back(const T &t) { append(t); }
inline void push_front(const T &t) { prepend(t); }
- void pop_back() { Q_ASSERT(!isEmpty()); erase(d->end() - 1); }
- void pop_front() { Q_ASSERT(!isEmpty()); erase(d->begin()); }
+ void pop_back() { removeLast(); }
+ void pop_front() { removeFirst(); }
inline bool empty() const
{ return d->size == 0; }
inline T& front() { return first(); }
@@ -556,6 +558,22 @@ void QVector<T>::append(const T &t)
}
template <typename T>
+inline void QVector<T>::removeLast()
+{
+ Q_ASSERT(!isEmpty());
+
+ if (d->alloc) {
+ if (d->ref.isShared()) {
+ reallocData(d->size - 1, int(d->alloc));
+ return;
+ }
+ if (QTypeInfo<T>::isComplex)
+ (d->data() + d->size - 1)->~T();
+ --d->size;
+ }
+}
+
+template <typename T>
typename QVector<T>::iterator QVector<T>::insert(iterator before, size_type n, const T &t)
{
int offset = std::distance(d->begin(), before);
@@ -604,6 +622,7 @@ typename QVector<T>::iterator QVector<T>::erase(iterator abegin, iterator aend)
// FIXME we could do a proper realloc, which copy constructs only needed data.
// FIXME we ara about to delete data maybe it is good time to shrink?
+ // FIXME the shrink is also an issue in removeLast, that is just a copy + reduce of this.
if (d->alloc) {
detach();
abegin = d->begin() + itemsUntouched;
@@ -813,6 +832,4 @@ Q_TEMPLATE_EXTERN template class Q_CORE_EXPORT QVector<QPoint>;
QT_END_NAMESPACE
-QT_END_HEADER
-
#endif // QVECTOR_H