QList - fix insert with iterator on shared instance
This patch ensures correct detach when insert with an iterator is called on a shared instance (i.e same behavior as QVector) Change-Id: Id660eacd3cc7b633456dfa989997bbad747e1df2 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
ea25495703
commit
97f867212f
@ -441,7 +441,11 @@ inline typename QList<T>::iterator QList<T>::insert(iterator before, const T &t)
|
|||||||
Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid");
|
Q_ASSERT_X(isValidIterator(before), "QList::insert", "The specified iterator argument 'before' is invalid");
|
||||||
|
|
||||||
int iBefore = int(before.i - reinterpret_cast<Node *>(p.begin()));
|
int iBefore = int(before.i - reinterpret_cast<Node *>(p.begin()));
|
||||||
Node *n = reinterpret_cast<Node *>(p.insert(iBefore));
|
Node *n = 0;
|
||||||
|
if (d->ref.isShared())
|
||||||
|
n = detach_helper_grow(iBefore, 1);
|
||||||
|
else
|
||||||
|
n = reinterpret_cast<Node *>(p.insert(iBefore));
|
||||||
QT_TRY {
|
QT_TRY {
|
||||||
node_construct(n, t);
|
node_construct(n, t);
|
||||||
} QT_CATCH(...) {
|
} QT_CATCH(...) {
|
||||||
|
@ -277,6 +277,7 @@ private slots:
|
|||||||
void setSharableComplex_data() const;
|
void setSharableComplex_data() const;
|
||||||
void setSharableComplex() const;
|
void setSharableComplex() const;
|
||||||
void eraseValidIteratorsOnSharedList() const;
|
void eraseValidIteratorsOnSharedList() const;
|
||||||
|
void insertWithValidIteratorsOnSharedList() const;
|
||||||
private:
|
private:
|
||||||
template<typename T> void length() const;
|
template<typename T> void length() const;
|
||||||
template<typename T> void append() const;
|
template<typename T> void append() const;
|
||||||
@ -1653,5 +1654,20 @@ void tst_QList::eraseValidIteratorsOnSharedList() const
|
|||||||
QCOMPARE(a.at(1), 50);
|
QCOMPARE(a.at(1), 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QList::insertWithValidIteratorsOnSharedList() const
|
||||||
|
{
|
||||||
|
QList<int> a, b;
|
||||||
|
a.push_back(10);
|
||||||
|
a.push_back(20);
|
||||||
|
a.push_back(30);
|
||||||
|
QList<int>::iterator i = a.begin();
|
||||||
|
++i;
|
||||||
|
b = a;
|
||||||
|
a.insert(i, 15);
|
||||||
|
QCOMPARE(a.size(), b.size() + 1);
|
||||||
|
QCOMPARE(b.at(1), 20);
|
||||||
|
QCOMPARE(a.at(1), 15);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QList)
|
QTEST_APPLESS_MAIN(tst_QList)
|
||||||
#include "tst_qlist.moc"
|
#include "tst_qlist.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user