QLinkedList - fix insert with iterator when the list is shared.
Before a call to erase on a shared instance would imply that the item was inserted into the shared data (i.e all instances) Change-Id: I655ccf04b1ad9bf82e6bfade58929538fa7df000 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
97f867212f
commit
c35b55f076
@ -453,6 +453,9 @@ int QLinkedList<T>::count(const T &t) const
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
typename QLinkedList<T>::iterator QLinkedList<T>::insert(iterator before, const T &t)
|
typename QLinkedList<T>::iterator QLinkedList<T>::insert(iterator before, const T &t)
|
||||||
{
|
{
|
||||||
|
if (d->ref.isShared())
|
||||||
|
before = detach_helper2(before);
|
||||||
|
|
||||||
Node *i = before.i;
|
Node *i = before.i;
|
||||||
Node *m = new Node(t);
|
Node *m = new Node(t);
|
||||||
m->n = i;
|
m->n = i;
|
||||||
|
@ -47,6 +47,7 @@ class tst_QLinkedList : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void eraseValidIteratorsOnSharedList() const;
|
void eraseValidIteratorsOnSharedList() const;
|
||||||
|
void insertWithIteratorsOnSharedList() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QLinkedList::eraseValidIteratorsOnSharedList() const
|
void tst_QLinkedList::eraseValidIteratorsOnSharedList() const
|
||||||
@ -73,5 +74,23 @@ void tst_QLinkedList::eraseValidIteratorsOnSharedList() const
|
|||||||
QCOMPARE(*r, 10); // Ensure that number 2 instance was removed;
|
QCOMPARE(*r, 10); // Ensure that number 2 instance was removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QLinkedList::insertWithIteratorsOnSharedList() const
|
||||||
|
{
|
||||||
|
QLinkedList<int> a, b;
|
||||||
|
a.append(5);
|
||||||
|
a.append(10);
|
||||||
|
a.append(20);
|
||||||
|
QLinkedList<int>::iterator i = a.begin();
|
||||||
|
++i;
|
||||||
|
++i;
|
||||||
|
b = a;
|
||||||
|
|
||||||
|
QLinkedList<int>::iterator i2 = a.insert(i, 15);
|
||||||
|
QCOMPARE(b.size(), 3);
|
||||||
|
QCOMPARE(a.size(), 4);
|
||||||
|
--i2;
|
||||||
|
QCOMPARE(*i2, 10);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QLinkedList)
|
QTEST_MAIN(tst_QLinkedList)
|
||||||
#include "tst_qlinkedlist.moc"
|
#include "tst_qlinkedlist.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user