From 0475460102411979ab51c365cb2bec2c05b69cb4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 22 Jun 2020 11:06:12 +0200 Subject: Use QList instead of QVector in corelib Applied to headers only. Source file to be changed separately. Omitted statemachine for now to avoid conflicts. Omitted qmetatype.h for now - to be handled later. Task-number: QTBUG-84469 Change-Id: I317376037a62467c313467d92955ad0b7473aa97 Reviewed-by: Sona Kurazyan --- src/corelib/tools/qcache.h | 6 +++--- src/corelib/tools/qeasingcurve.h | 4 ++-- src/corelib/tools/qflatmap_p.h | 10 ++++----- src/corelib/tools/qhash.h | 44 ++++++++++++++------------------------ src/corelib/tools/qringbuffer_p.h | 4 ++-- src/corelib/tools/qstack.h | 9 ++++---- src/corelib/tools/qversionnumber.h | 30 +++++++++++--------------- 7 files changed, 44 insertions(+), 63 deletions(-) (limited to 'src/corelib/tools') diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 8cf6598f10..ac7760be0b 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -205,11 +205,11 @@ public: inline qsizetype size() const noexcept { return d.size; } inline qsizetype count() const noexcept { return d.size; } inline bool isEmpty() const noexcept { return !d.size; } - inline QVector keys() const + inline QList keys() const { - QVector k; + QList k; if (d.size) { - k.reserve(typename QVector::size_type(d.size)); + k.reserve(typename QList::size_type(d.size)); for (auto it = d.begin(); it != d.end(); ++it) k << it.node()->key; } diff --git a/src/corelib/tools/qeasingcurve.h b/src/corelib/tools/qeasingcurve.h index 81833a758f..e6ee7b56d5 100644 --- a/src/corelib/tools/qeasingcurve.h +++ b/src/corelib/tools/qeasingcurve.h @@ -44,8 +44,8 @@ QT_REQUIRE_CONFIG(easingcurve); +#include #include -#include QT_BEGIN_NAMESPACE @@ -100,7 +100,7 @@ public: void addCubicBezierSegment(const QPointF & c1, const QPointF & c2, const QPointF & endPoint); void addTCBSegment(const QPointF &nextPoint, qreal t, qreal c, qreal b); - QVector toCubicSpline() const; + QList toCubicSpline() const; Type type() const; void setType(Type type); diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h index 82a1068d34..bf0efb2543 100644 --- a/src/corelib/tools/qflatmap_p.h +++ b/src/corelib/tools/qflatmap_p.h @@ -51,7 +51,7 @@ // We mean it. // -#include "qvector.h" +#include "qlist.h" #include #include @@ -66,7 +66,7 @@ QT_BEGIN_NAMESPACE /* QFlatMap provides an associative container backed by sorted sequential - containers. By default, QVector is used. + containers. By default, QList is used. Keys and values are stored in two separate containers. This provides improved cache locality for key iteration and makes keys() and values() fast @@ -105,10 +105,8 @@ public: } }; -template , - class KeyContainer = QVector, - class MappedContainer = QVector> +template, class KeyContainer = QList, + class MappedContainer = QList> class QFlatMap : private QFlatMapValueCompare { using full_map_t = QFlatMap; diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 2c39a9dfc8..2de3989eb2 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -40,12 +40,12 @@ #ifndef QHASH_H #define QHASH_H -#include -#include -#include -#include #include +#include +#include +#include #include +#include #include @@ -897,13 +897,10 @@ public: return value(key); } - QVector keys() const - { - return QVector(keyBegin(), keyEnd()); - } - QVector keys(const T &value) const + QList keys() const { return QList(keyBegin(), keyEnd()); } + QList keys(const T &value) const { - QVector res; + QList res; const_iterator i = begin(); while (i != end()) { if (i.value() == value) @@ -912,10 +909,7 @@ public: } return res; } - QVector values() const - { - return QVector(begin(), end()); - } + QList values() const { return QList(begin(), end()); } class const_iterator; @@ -1381,9 +1375,9 @@ public: return value(key); } - QVector uniqueKeys() const + QList uniqueKeys() const { - QVector res; + QList res; if (d) { auto i = d->begin(); while (i != d->end()) { @@ -1394,13 +1388,10 @@ public: return res; } - QVector keys() const + QList keys() const { return QList(keyBegin(), keyEnd()); } + QList keys(const T &value) const { - return QVector(keyBegin(), keyEnd()); - } - QVector keys(const T &value) const - { - QVector res; + QList res; const_iterator i = begin(); while (i != end()) { if (i.value()->contains(value)) @@ -1409,13 +1400,10 @@ public: } return res; } - QVector values() const - { - return QVector(begin(), end()); - } - QVector values(const Key &key) const + QList values() const { return QList(begin(), end()); } + QList values(const Key &key) const { - QVector values; + QList values; if (d) { Node *n = d->findNode(key); if (n) { diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 838cb31697..85a3882a3c 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -53,7 +53,7 @@ #include #include -#include +#include QT_BEGIN_NAMESPACE @@ -265,7 +265,7 @@ public: } private: - QVector buffers; + QList buffers; qint64 bufferSize; int basicBlockSize; }; diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h index e59212aa2a..a0e39f8ece 100644 --- a/src/corelib/tools/qstack.h +++ b/src/corelib/tools/qstack.h @@ -40,18 +40,17 @@ #ifndef QSTACK_H #define QSTACK_H -#include +#include QT_BEGIN_NAMESPACE - template -class QStack : public QVector +class QStack : public QList { public: // compiler-generated special member functions are fine! - inline void swap(QStack &other) noexcept { QVector::swap(other); } // prevent QVector<->QStack swaps - inline void push(const T &t) { QVector::append(t); } + inline void swap(QStack &other) noexcept { QList::swap(other); } // prevent QList<->QStack swaps + inline void push(const T &t) { QList::append(t); } T pop(); T &top(); const T &top() const; diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index f4e384c8dc..f8a2d8eae8 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -42,10 +42,10 @@ #ifndef QVERSIONNUMBER_H #define QVERSIONNUMBER_H +#include +#include #include #include -#include -#include #include #include @@ -84,24 +84,24 @@ class QVersionNumber union { quintptr dummy; qint8 inline_segments[sizeof(void*)]; - QVector *pointer_segments; + QList *pointer_segments; }; // set the InlineSegmentMarker and set length to zero SegmentStorage() noexcept : dummy(1) {} - SegmentStorage(const QVector &seg) + SegmentStorage(const QList &seg) { if (dataFitsInline(seg.begin(), seg.size())) setInlineData(seg.begin(), seg.size()); else - pointer_segments = new QVector(seg); + pointer_segments = new QList(seg); } SegmentStorage(const SegmentStorage &other) { if (other.isUsingPointer()) - pointer_segments = new QVector(*other.pointer_segments); + pointer_segments = new QList(*other.pointer_segments); else dummy = other.dummy; } @@ -111,7 +111,7 @@ class QVersionNumber if (isUsingPointer() && other.isUsingPointer()) { *pointer_segments = *other.pointer_segments; } else if (other.isUsingPointer()) { - pointer_segments = new QVector(*other.pointer_segments); + pointer_segments = new QList(*other.pointer_segments); } else { if (isUsingPointer()) delete pointer_segments; @@ -132,19 +132,19 @@ class QVersionNumber return *this; } - explicit SegmentStorage(QVector &&seg) + explicit SegmentStorage(QList &&seg) { if (dataFitsInline(seg.begin(), seg.size())) setInlineData(seg.begin(), seg.size()); else - pointer_segments = new QVector(std::move(seg)); + pointer_segments = new QList(std::move(seg)); } SegmentStorage(std::initializer_list args) { if (dataFitsInline(args.begin(), int(args.size()))) { setInlineData(args.begin(), int(args.size())); } else { - pointer_segments = new QVector(args); + pointer_segments = new QList(args); } } @@ -218,15 +218,11 @@ public: inline QVersionNumber() noexcept : m_segments() {} - inline explicit QVersionNumber(const QVector &seg) - : m_segments(seg) - {} + inline explicit QVersionNumber(const QList &seg) : m_segments(seg) { } // compiler-generated copy/move ctor/assignment operators and the destructor are ok - explicit QVersionNumber(QVector &&seg) - : m_segments(std::move(seg)) - {} + explicit QVersionNumber(QList &&seg) : m_segments(std::move(seg)) { } inline QVersionNumber(std::initializer_list args) : m_segments(args) @@ -258,7 +254,7 @@ public: Q_REQUIRED_RESULT Q_CORE_EXPORT QVersionNumber normalized() const; - Q_REQUIRED_RESULT Q_CORE_EXPORT QVector segments() const; + Q_REQUIRED_RESULT Q_CORE_EXPORT QList segments() const; Q_REQUIRED_RESULT inline int segmentAt(int index) const noexcept { return (m_segments.size() > index) ? m_segments.at(index) : 0; } -- cgit v1.2.3