summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2010-02-20 09:04:29 +0100
committerThiago Macieira <thiago.macieira@nokia.com>2010-02-20 09:04:29 +0100
commit30b45ba2b11342a9e7cc06b68237b68a68955213 (patch)
tree1018c188375b3217b31abe9b7a0883ee1184a447 /src/corelib/tools/qlist.h
parentce27cf24539e0c7971937e55d8539496ad51ee52 (diff)
parent8f10ca802dee1ed110f301191c4a56a85575033c (diff)
Merge remote branch 'origin/master' into qt-master-from-4.6
Conflicts: configure.exe src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp src/opengl/qgl.cpp
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 261c369fd3..5364e8eee8 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -72,9 +72,10 @@ struct Q_CORE_EXPORT QListData {
};
enum { DataHeaderSize = sizeof(Data) - sizeof(void *) };
+ Data *detach(int alloc);
Data *detach(); // remove in 5.0
Data *detach2(); // remove in 5.0
- Data *detach3();
+ Data *detach3(); // remove in 5.0
void realloc(int alloc);
static Data shared_null;
Data *d;
@@ -140,6 +141,7 @@ public:
const T &operator[](int i) const;
T &operator[](int i);
+ void reserve(int size);
void append(const T &t);
void append(const QList<T> &t);
void prepend(const T &t);
@@ -331,6 +333,7 @@ public:
#endif
private:
+ void detach_helper(int alloc);
void detach_helper();
void free(QListData::Data *d);
@@ -464,6 +467,17 @@ inline T QList<T>::takeLast()
{ T t = last(); removeLast(); return t; }
template <typename T>
+Q_OUTOFLINE_TEMPLATE void QList<T>::reserve(int alloc)
+{
+ if (d->alloc < alloc) {
+ if (d->ref != 1)
+ detach_helper(alloc);
+ else
+ p.realloc(alloc);
+ }
+}
+
+template <typename T>
Q_OUTOFLINE_TEMPLATE void QList<T>::append(const T &t)
{
detach();
@@ -575,11 +589,20 @@ Q_OUTOFLINE_TEMPLATE QList<T> QList<T>::mid(int pos, int alength) const
alength = size() - pos;
if (pos == 0 && alength == size())
return *this;
- QList<T> cpy;
if (pos + alength > size())
alength = size() - pos;
- for (int i = pos; i < pos + alength; ++i)
- cpy += at(i);
+ QList<T> cpy;
+ cpy.reserve(alength);
+ cpy.d->end = alength;
+ QT_TRY {
+ cpy.node_copy(reinterpret_cast<Node *>(cpy.p.begin()),
+ reinterpret_cast<Node *>(cpy.p.end()),
+ reinterpret_cast<Node *>(p.begin() + pos));
+ } QT_CATCH(...) {
+ // restore the old end
+ cpy.d->end = 0;
+ QT_RETHROW;
+ }
return cpy;
}
@@ -599,10 +622,10 @@ Q_OUTOFLINE_TEMPLATE T QList<T>::value(int i, const T& defaultValue) const
}
template <typename T>
-Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper()
+Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper(int alloc)
{
Node *n = reinterpret_cast<Node *>(p.begin());
- QListData::Data *x = p.detach3();
+ QListData::Data *x = p.detach(alloc);
QT_TRY {
node_copy(reinterpret_cast<Node *>(p.begin()), reinterpret_cast<Node *>(p.end()), n);
} QT_CATCH(...) {
@@ -616,6 +639,12 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper()
}
template <typename T>
+Q_OUTOFLINE_TEMPLATE void QList<T>::detach_helper()
+{
+ detach_helper(d->alloc);
+}
+
+template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T>::~QList()
{
if (d && !d->ref.deref())