diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-04-03 15:44:59 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-18 02:08:13 +0200 |
commit | bf3e80023a70b86c2bff793cb8dd86055236ddeb (patch) | |
tree | dbfbf5ae5e77f04988d50debf8ff3de7b549f541 /src/corelib/tools/qiterator.h | |
parent | 1aede2d7fc5192776d5c8c9e625478d6d3f55446 (diff) |
Stop using setSharable in the Java-style mutable iterators
First and foremost, the STL-style iterators don't do this. Those don't
provide a guarantee that the container won't get shared again while the
iterator is active.
Second, there's no protection against a second mutable iterator being
created and resetting the sharable flag back to true.
[ChangeLog][Important behavior changes] The mutable Java-style iterators
like QListMutableIterator and QHashMutableIterator no longer set the
parent container to unsharable mode. If you create a copy of the
container being iterated on after the iterator, any changes done with
the iterator might affect the copy too.
Discussed-on: http://lists.qt-project.org/pipermail/development/2014-February/015724.html
Change-Id: Iccfe411d5558c85ae459cff944215614c392388e
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Diffstat (limited to 'src/corelib/tools/qiterator.h')
-rw-r--r-- | src/corelib/tools/qiterator.h | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/corelib/tools/qiterator.h b/src/corelib/tools/qiterator.h index 3b86edd750..86b78eb522 100644 --- a/src/corelib/tools/qiterator.h +++ b/src/corelib/tools/qiterator.h @@ -87,12 +87,9 @@ class QMutable##C##Iterator \ public: \ inline QMutable##C##Iterator(Q##C<T> &container) \ : c(&container) \ - { c->setSharable(false); i = c->begin(); n = c->end(); } \ - inline ~QMutable##C##Iterator() \ - { c->setSharable(true); } \ + { i = c->begin(); n = c->end(); } \ inline QMutable##C##Iterator &operator=(Q##C<T> &container) \ - { c->setSharable(true); c = &container; c->setSharable(false); \ - i = c->begin(); n = c->end(); return *this; } \ + { c = &container; i = c->begin(); n = c->end(); return *this; } \ inline void toFront() { i = c->begin(); n = c->end(); } \ inline void toBack() { i = c->end(); n = i; } \ inline bool hasNext() const { return c->constEnd() != const_iterator(i); } \ @@ -160,11 +157,9 @@ class QMutable##C##Iterator \ public: \ inline QMutable##C##Iterator(Q##C<Key,T> &container) \ : c(&container) \ - { c->setSharable(false); i = c->begin(); n = c->end(); } \ - inline ~QMutable##C##Iterator() \ - { c->setSharable(true); } \ + { i = c->begin(); n = c->end(); } \ inline QMutable##C##Iterator &operator=(Q##C<Key,T> &container) \ - { c->setSharable(true); c = &container; c->setSharable(false); i = c->begin(); n = c->end(); return *this; } \ + { c = &container; i = c->begin(); n = c->end(); return *this; } \ inline void toFront() { i = c->begin(); n = c->end(); } \ inline void toBack() { i = c->end(); n = c->end(); } \ inline bool hasNext() const { return const_iterator(i) != c->constEnd(); } \ |