summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r--src/corelib/tools/qlist.h30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index b4c35b8d35..5c9845539a 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -750,18 +750,26 @@ Q_OUTOFLINE_TEMPLATE void QList<T>::clear()
template <typename T>
Q_OUTOFLINE_TEMPLATE int QList<T>::removeAll(const T &_t)
{
- detachShared();
+ int index = indexOf(_t);
+ if (index == -1)
+ return 0;
+
const T t = _t;
- int removedCount=0, i=0;
- Node *n;
- while (i < p.size())
- if ((n = reinterpret_cast<Node *>(p.at(i)))->t() == t) {
- node_destruct(n);
- p.remove(i);
- ++removedCount;
- } else {
- ++i;
- }
+ detach();
+
+ Node *i = reinterpret_cast<Node *>(p.at(index));
+ Node *e = reinterpret_cast<Node *>(p.end());
+ Node *n = i;
+ node_destruct(i);
+ while (++i != e) {
+ if (i->t() == t)
+ node_destruct(i);
+ else
+ *n++ = *i;
+ }
+
+ int removedCount = e - n;
+ d->end -= removedCount;
return removedCount;
}