diff options
Diffstat (limited to 'src/corelib/tools/qmap.h')
-rw-r--r-- | src/corelib/tools/qmap.h | 102 |
1 files changed, 38 insertions, 64 deletions
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 0c69d13295..848ba5c4d4 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -180,7 +180,7 @@ inline QMapNode<Key, T> *QMapNode<Key, T>::upperBound(const Key &akey) struct Q_CORE_EXPORT QMapDataBase { QtPrivate::RefCount ref; - int size; + qsizetype size; QMapNodeBase header; QMapNodeBase *mostLeftNode; @@ -190,8 +190,8 @@ struct Q_CORE_EXPORT QMapDataBase void freeNodeAndRebalance(QMapNodeBase *z); void recalcMostLeftNode(); - QMapNodeBase *createNode(int size, int alignment, QMapNodeBase *parent, bool left); - void freeTree(QMapNodeBase *root, int alignment); + QMapNodeBase *createNode(size_t size, size_t alignment, QMapNodeBase *parent, bool left); + void freeTree(QMapNodeBase *root, size_t alignment); static const QMapDataBase shared_null; @@ -219,7 +219,7 @@ struct QMapData : public QMapDataBase Node *createNode(const Key &k, const T &v, Node *parent = nullptr, bool left = false) { - Node *n = static_cast<Node *>(QMapDataBase::createNode(sizeof(Node), Q_ALIGNOF(Node), + Node *n = static_cast<Node *>(QMapDataBase::createNode(sizeof(Node), alignof(Node), parent, left)); QT_TRY { new (&n->key) Key(k); @@ -243,7 +243,7 @@ struct QMapData : public QMapDataBase void destroy() { if (root()) { root()->destroySubTree(); - freeTree(header.left, Q_ALIGNOF(Node)); + freeTree(header.left, alignof(Node)); } freeData(this); } @@ -350,33 +350,22 @@ public: bool operator==(const QMap<Key, T> &other) const; inline bool operator!=(const QMap<Key, T> &other) const { return !(*this == other); } - inline int size() const { return d->size; } + inline qsizetype size() const { return d->size; } inline bool isEmpty() const { return d->size == 0; } inline void detach() { if (d->ref.isShared()) detach_helper(); } inline bool isDetached() const { return !d->ref.isShared(); } -#if !defined(QT_NO_UNSHARABLE_CONTAINERS) - inline void setSharable(bool sharable) - { - if (sharable == d->ref.isSharable()) - return; - if (!sharable) - detach(); - // Don't call on shared_null - d->ref.setSharable(sharable); - } -#endif inline bool isSharedWith(const QMap<Key, T> &other) const { return d == other.d; } void clear(); - int remove(const Key &key); + qsizetype remove(const Key &key); T take(const Key &key); bool contains(const Key &key) const; - const Key key(const T &value, const Key &defaultKey = Key()) const; - const T value(const Key &key, const T &defaultValue = T()) const; + Key key(const T &value, const Key &defaultKey = Key()) const; + T value(const Key &key, const T &defaultValue = T()) const; T &operator[](const Key &key); const T operator[](const Key &key) const; @@ -387,7 +376,7 @@ public: QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") QList<Key> uniqueKeys() const; QT_DEPRECATED_VERSION_X_5_15("Use QMultiMap for maps storing multiple values with the same key.") QList<T> values(const Key &key) const; #endif - int count(const Key &key) const; + qsizetype count(const Key &key) const; inline const Key &firstKey() const { Q_ASSERT(!isEmpty()); return constBegin().key(); } @@ -440,20 +429,15 @@ public: i = i->previousNode(); return r; } - inline iterator operator+(int j) const + inline iterator operator+(qsizetype j) const { iterator r = *this; if (j > 0) while (j--) ++r; else while (j++) --r; return r; } - inline iterator operator-(int j) const { return operator+(-j); } - inline iterator &operator+=(int j) { return *this = *this + j; } - inline iterator &operator-=(int j) { return *this = *this - j; } - friend inline iterator operator+(int j, iterator k) { return k + j; } + inline iterator operator-(qsizetype j) const { return operator+(-j); } + inline iterator &operator+=(qsizetype j) { return *this = *this + j; } + inline iterator &operator-=(qsizetype j) { return *this = *this - j; } + friend inline iterator operator+(qsizetype j, iterator k) { return k + j; } -#ifndef QT_STRICT_ITERATORS - public: - inline bool operator==(const const_iterator &o) const - { return i == o.i; } - inline bool operator!=(const const_iterator &o) const - { return i != o.i; } -#endif + inline bool operator==(const const_iterator &o) const { return i == o.i; } + inline bool operator!=(const const_iterator &o) const { return i != o.i; } friend class QMap<Key, T>; friend class QMultiMap<Key, T>; }; @@ -473,12 +457,7 @@ public: Q_DECL_CONSTEXPR inline const_iterator() : i(nullptr) { } inline const_iterator(const Node *node) : i(node) { } -#ifdef QT_STRICT_ITERATORS - explicit inline const_iterator(const iterator &o) -#else - inline const_iterator(const iterator &o) -#endif - { i = o.i; } + inline const_iterator(const iterator &o) { i = o.i; } inline const Key &key() const { return i->key; } inline const T &value() const { return i->value; } @@ -505,18 +484,13 @@ public: i = i->previousNode(); return r; } - inline const_iterator operator+(int j) const + inline const_iterator operator+(qsizetype j) const { const_iterator r = *this; if (j > 0) while (j--) ++r; else while (j++) --r; return r; } - inline const_iterator operator-(int j) const { return operator+(-j); } - inline const_iterator &operator+=(int j) { return *this = *this + j; } - inline const_iterator &operator-=(int j) { return *this = *this - j; } - friend inline const_iterator operator+(int j, const_iterator k) { return k + j; } - -#ifdef QT_STRICT_ITERATORS - private: - inline bool operator==(const iterator &o) const { return operator==(const_iterator(o)); } - inline bool operator!=(const iterator &o) const { return operator!=(const_iterator(o)); } -#endif + inline const_iterator operator-(qsizetype j) const { return operator+(-j); } + inline const_iterator &operator+=(qsizetype j) { return *this = *this + j; } + inline const_iterator &operator-=(qsizetype j) { return *this = *this - j; } + friend inline const_iterator operator+(qsizetype j, const_iterator k) { return k + j; } + friend class QMap<Key, T>; friend class QMultiMap<Key, T>; }; @@ -573,7 +547,7 @@ public: // more Qt typedef iterator Iterator; typedef const_iterator ConstIterator; - inline int count() const { return d->size; } + inline qsizetype count() const { return d->size; } iterator find(const Key &key); const_iterator find(const Key &key) const; const_iterator constFind(const Key &key) const; @@ -594,7 +568,7 @@ public: typedef Key key_type; typedef T mapped_type; typedef qptrdiff difference_type; - typedef int size_type; + typedef qsizetype size_type; inline bool empty() const { return isEmpty(); } QPair<iterator, iterator> equal_range(const Key &akey); QPair<const_iterator, const_iterator> equal_range(const Key &akey) const; @@ -656,7 +630,7 @@ QT_WARNING_PUSH QT_WARNING_DISABLE_CLANG("-Wreturn-stack-address") template <class Key, class T> -Q_INLINE_TEMPLATE const T QMap<Key, T>::value(const Key &akey, const T &adefaultValue) const +Q_INLINE_TEMPLATE T QMap<Key, T>::value(const Key &akey, const T &adefaultValue) const { Node *n = d->findNode(akey); return n ? n->value : adefaultValue; @@ -681,7 +655,7 @@ Q_INLINE_TEMPLATE T &QMap<Key, T>::operator[](const Key &akey) } template <class Key, class T> -Q_INLINE_TEMPLATE int QMap<Key, T>::count(const Key &akey) const +Q_INLINE_TEMPLATE qsizetype QMap<Key, T>::count(const Key &akey) const { Node *firstNode; Node *lastNode; @@ -904,10 +878,10 @@ void QMap<Key, T>::dump() const #endif template <class Key, class T> -Q_OUTOFLINE_TEMPLATE int QMap<Key, T>::remove(const Key &akey) +Q_OUTOFLINE_TEMPLATE qsizetype QMap<Key, T>::remove(const Key &akey) { detach(); - int n = 0; + qsizetype n = 0; while (Node *node = d->findNode(akey)) { d->deleteNode(node); ++n; @@ -940,7 +914,7 @@ Q_OUTOFLINE_TEMPLATE typename QMap<Key, T>::iterator QMap<Key, T>::erase(iterato if (d->ref.isShared()) { const_iterator oldBegin = constBegin(); const_iterator old = const_iterator(it); - int backStepsWithSameKey = 0; + qsizetype backStepsWithSameKey = 0; while (old != oldBegin) { --old; @@ -1005,7 +979,7 @@ Q_OUTOFLINE_TEMPLATE QList<Key> QMap<Key, T>::keys(const T &avalue) const } template <class Key, class T> -Q_OUTOFLINE_TEMPLATE const Key QMap<Key, T>::key(const T &avalue, const Key &defaultKey) const +Q_OUTOFLINE_TEMPLATE Key QMap<Key, T>::key(const T &avalue, const Key &defaultKey) const { const_iterator i = begin(); while (i != end()) { @@ -1157,9 +1131,9 @@ public: bool contains(const Key &key, const T &value) const; - int remove(const Key &key, const T &value); + qsizetype remove(const Key &key, const T &value); - int count(const Key &key, const T &value) const; + qsizetype count(const Key &key, const T &value) const; typename QMap<Key, T>::iterator find(const Key &key, const T &value) { typename QMap<Key, T>::iterator i(find(key)); @@ -1315,9 +1289,9 @@ Q_INLINE_TEMPLATE bool QMultiMap<Key, T>::contains(const Key &key, const T &valu } template <class Key, class T> -Q_INLINE_TEMPLATE int QMultiMap<Key, T>::remove(const Key &key, const T &value) +Q_INLINE_TEMPLATE qsizetype QMultiMap<Key, T>::remove(const Key &key, const T &value) { - int n = 0; + qsizetype n = 0; typename QMap<Key, T>::iterator i(find(key)); typename QMap<Key, T>::iterator end(QMap<Key, T>::end()); while (i != end && !qMapLessThanKey<Key>(key, i.key())) { @@ -1332,9 +1306,9 @@ Q_INLINE_TEMPLATE int QMultiMap<Key, T>::remove(const Key &key, const T &value) } template <class Key, class T> -Q_INLINE_TEMPLATE int QMultiMap<Key, T>::count(const Key &key, const T &value) const +Q_INLINE_TEMPLATE qsizetype QMultiMap<Key, T>::count(const Key &key, const T &value) const { - int n = 0; + qsizetype n = 0; typename QMap<Key, T>::const_iterator i(constFind(key)); typename QMap<Key, T>::const_iterator end(QMap<Key, T>::constEnd()); while (i != end && !qMapLessThanKey<Key>(key, i.key())) { |