diff options
author | Liang Qi <liang.qi@qt.io> | 2020-01-04 15:32:34 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2020-01-04 15:32:34 +0100 |
commit | a503bf54705d89204007e8f887b668fe5ef519fc (patch) | |
tree | b2d1a452da39450eac78a1aeb1df116a73f64b23 /src/corelib/tools/qmap.h | |
parent | e65c43fd0ffa57248e7d750570b7deae171a82f5 (diff) | |
parent | 1f87fb359fdff14e42662384a9c8a0bcb3837671 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
src/corelib/tools/qvector.h
Make QVector(DataPointer dd) public to be able to properly merge
5b4b437b30b320e2cd7c9a566999a39772e5d431 from 5.15 into dev.
src/widgets/kernel/qapplication.cpp
tests/auto/tools/moc/allmocs_baseline_in.json
Done-With: Christian Ehrlicher <ch.ehrlicher@gmx.de>
Change-Id: I929ba7c036d570382d0454c2c75f6f0d96ddbc01
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index f169ed5e49..5cc3116903 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -552,6 +552,7 @@ public: const_iterator upperBound(const Key &key) const; iterator insert(const Key &key, const T &value); iterator insert(const_iterator pos, const Key &key, const T &value); + void insert(const QMap<Key, T> &map); iterator insertMulti(const Key &key, const T &value); iterator insertMulti(const_iterator pos, const Key &akey, const T &avalue); QMap<Key, T> &unite(const QMap<Key, T> &other); @@ -763,6 +764,49 @@ typename QMap<Key, T>::iterator QMap<Key, T>::insert(const_iterator pos, const K } template <class Key, class T> +Q_INLINE_TEMPLATE void QMap<Key, T>::insert(const QMap<Key, T> &map) +{ + if (d == map.d) + return; + + detach(); + + Node *n = d->root(); + auto it = map.cbegin(); + const auto e = map.cend(); + while (it != e) { + // Insertion here is based on insert(Key, T) + auto parent = d->end(); + bool left = true; + Node *lastNode = nullptr; + while (n) { + parent = n; + if (!qMapLessThanKey(n->key, it.key())) { + lastNode = n; + n = n->leftNode(); + left = true; + } else { + n = n->rightNode(); + left = false; + } + } + if (lastNode && !qMapLessThanKey(it.key(), lastNode->key)) { + lastNode->value = it.value(); + n = lastNode; + } else { + n = d->createNode(it.key(), it.value(), parent, left); + } + ++it; + if (it != e) { + // Move back up the tree until we find the next branch or node which is + // relevant for the next key. + while (n != d->root() && qMapLessThanKey(n->key, it.key())) + n = static_cast<Node *>(n->parent()); + } + } +} + +template <class Key, class T> Q_INLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::insertMulti(const Key &akey, const T &avalue) { |