QHash: don't detach from null when calling begin()
We allocate space just to traverse over an empty list, then the iterator is turned into a sentinel that matches end(). Change-Id: I45a452cd6421646876245ba3b4f957f1a3bb7f37 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
0b5874bc96
commit
e138a01aef
@ -1234,7 +1234,7 @@ public:
|
||||
typedef QKeyValueIterator<const Key&, T&, iterator> key_value_iterator;
|
||||
|
||||
// STL style
|
||||
inline iterator begin() { detach(); return iterator(d->begin()); }
|
||||
inline iterator begin() { if (!d) return iterator(); detach(); return iterator(d->begin()); }
|
||||
inline const_iterator begin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
inline const_iterator cbegin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
inline const_iterator constBegin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
@ -1982,7 +1982,7 @@ public:
|
||||
typedef QKeyValueIterator<const Key&, T&, iterator> key_value_iterator;
|
||||
|
||||
// STL style
|
||||
inline iterator begin() { detach(); return iterator(d->begin()); }
|
||||
inline iterator begin() { if (!d) return iterator(); detach(); return iterator(d->begin()); }
|
||||
inline const_iterator begin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
inline const_iterator cbegin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
inline const_iterator constBegin() const noexcept { return d ? const_iterator(d->begin()): const_iterator(); }
|
||||
|
@ -1675,9 +1675,9 @@ void iteratorsInEmptyHashTestMethod()
|
||||
QVERIFY(it7 == Iter());
|
||||
QVERIFY(!hash3.isDetached());
|
||||
|
||||
Iter it8 = hash3.begin(); // calls detach()
|
||||
Iter it8 = hash3.begin();
|
||||
QVERIFY(it8 == Iter());
|
||||
QVERIFY(hash3.isDetached());
|
||||
QVERIFY(!hash3.isDetached()); // No detach from empty hash just for iteration!
|
||||
}
|
||||
|
||||
void tst_QHash::iteratorsInEmptyHash()
|
||||
@ -1887,9 +1887,9 @@ void keyValueIteratorInEmptyHashTestMethod()
|
||||
QVERIFY(it5 == KeyValueIter());
|
||||
QVERIFY(!hash3.isDetached());
|
||||
|
||||
KeyValueIter it6 = hash3.keyValueBegin(); // calls detach()
|
||||
KeyValueIter it6 = hash3.keyValueBegin();
|
||||
QVERIFY(it6 == KeyValueIter());
|
||||
QVERIFY(hash3.isDetached());
|
||||
QVERIFY(!hash3.isDetached()); // No detach in empty hash just for iteration
|
||||
}
|
||||
|
||||
void tst_QHash::keyValueIteratorInEmptyHash()
|
||||
|
@ -507,7 +507,7 @@ void tst_QSet::begin()
|
||||
QVERIFY(i == j);
|
||||
QVERIFY(k == j);
|
||||
QVERIFY(!set3.isDetached());
|
||||
QVERIFY(set4.isDetached());
|
||||
QVERIFY(!set4.isDetached()); // d-ptr is null
|
||||
}
|
||||
|
||||
set4.insert(1);
|
||||
|
Loading…
x
Reference in New Issue
Block a user