diff options
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 8c15afd9f8..c030a76666 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -913,6 +913,27 @@ Q_OUTOFLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::erase(iterato Q_ASSERT_X(isValidIterator(const_iterator(it)), "QMap::erase", "The specified iterator argument 'it' is invalid"); + if (d->ref.isShared()) { + const_iterator oldBegin = constBegin(); + const_iterator old = const_iterator(it); + int backStepsWithSameKey = 0; + + while (old != oldBegin) { + --old; + if (qMapLessThanKey(old.key(), it.key())) + break; + ++backStepsWithSameKey; + } + + it = find(old.key()); // ensures detach + Q_ASSERT_X(it != iterator(d->end()), "QMap::erase", "Unable to locate same key in erase after detach."); + + while (backStepsWithSameKey > 0) { + ++it; + --backStepsWithSameKey; + } + } + Node *n = it.i; ++it; d->deleteNode(n); |