summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2021-12-07 15:48:35 +0100
committerMarc Mutz <marc.mutz@qt.io>2021-12-11 03:15:11 +0000
commit85e92f2e5f1d90fceac5d83cc97f8efc4f276397 (patch)
treeab4f2ca4cfda41d5c4e1c423ab9ef5813e7c63d5
parentbae0a159d8657885e46751710519ca0c3cc69092 (diff)
QVarLengthArray: deprecate prepend()
All Qt 6 containers have "fast" prepend these days. Except QVLA. Instead of enabling "fast" prepend for QVLA, slowing down idiomatic QVLA use, simply deprecate prepend(). There appear to be no users of this function in qtbase outside tests. [ChangeLog][QtCore][Deprecation Notices][QVarLengthArray] Deprecated prepend() because QVarLengthArray is the only Qt container without a "fast" prepend. If you require that functionality, even though it's a linear operation, then use insert(cbegin(), ~~~) instead. Change-Id: I39ff1dd7d4de7fc08d5380a5a7450dd8c8996fe2 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/corelib/tools/qvarlengtharray.h6
-rw-r--r--src/corelib/tools/qvarlengtharray.qdoc2
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp10
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp11
4 files changed, 26 insertions, 3 deletions
diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h
index 4d25287887..79ecdaee7d 100644
--- a/src/corelib/tools/qvarlengtharray.h
+++ b/src/corelib/tools/qvarlengtharray.h
@@ -271,8 +271,12 @@ public:
inline QVarLengthArray<T, Prealloc> &operator+=(T &&t)
{ append(std::move(t)); return *this; }
+#if QT_DEPRECATED_SINCE(6, 3)
+ QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
void prepend(T &&t);
+ QT_DEPRECATED_VERSION_X_6_3("This is slow. If you must, use insert(cbegin(), ~~~) instead.")
void prepend(const T &t);
+#endif
void insert(qsizetype i, T &&t);
void insert(qsizetype i, const T &t);
void insert(qsizetype i, qsizetype n, const T &t);
@@ -596,12 +600,14 @@ template <class T, qsizetype Prealloc>
template <typename Predicate>
inline qsizetype QVarLengthArray<T, Prealloc>::removeIf(Predicate pred)
{ return QtPrivate::sequential_erase_if(*this, pred); }
+#if QT_DEPRECATED_SINCE(6, 3)
template <class T, qsizetype Prealloc>
inline void QVarLengthArray<T, Prealloc>::prepend(T &&t)
{ insert(cbegin(), std::move(t)); }
template <class T, qsizetype Prealloc>
inline void QVarLengthArray<T, Prealloc>::prepend(const T &t)
{ insert(begin(), 1, t); }
+#endif
template <class T, qsizetype Prealloc>
inline void QVarLengthArray<T, Prealloc>::replace(qsizetype i, const T &t)
diff --git a/src/corelib/tools/qvarlengtharray.qdoc b/src/corelib/tools/qvarlengtharray.qdoc
index b7e6cd6d6e..de57daf4e4 100644
--- a/src/corelib/tools/qvarlengtharray.qdoc
+++ b/src/corelib/tools/qvarlengtharray.qdoc
@@ -545,6 +545,8 @@
\fn template<class T, qsizetype Prealloc> void QVarLengthArray<T, Prealloc>::prepend(T &&value)
\since 4.8
+ \deprecated [6.3] This is slow. If you must, use \c{insert(cbegin(), ~~~)} instead.
+
Inserts \a value at the beginning of the array.
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index fd857aa875..7306e036a9 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -312,6 +312,11 @@ static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveHashK>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashV>);
static_assert(!QTypeTraits::has_operator_equal_v<NoCmpRecursiveMultiHashK>);
+template <typename T>
+constexpr inline bool has_prepend_v = true;
+template <typename T, qsizetype N>
+constexpr inline bool has_prepend_v<QVarLengthArray<T,N>> = false; // deprecated in Qt 6.3
+
void tst_Collections::typeinfo()
{
QVERIFY(QTypeInfo<int*>::isPointer);
@@ -3452,7 +3457,10 @@ template<class Container> void insert_remove_loop_impl()
t.append(T(IntOrString(1)));
t << (T(IntOrString(2)));
t += (T(IntOrString(3)));
- t.prepend(T(IntOrString(4)));
+ if constexpr (has_prepend_v<Container>)
+ t.prepend(T(IntOrString(4)));
+ else
+ t.insert(t.cbegin(), T(IntOrString(4)));
t.insert(2, 3 , T(IntOrString(5)));
t.insert(4, T(IntOrString(6)));
t.insert(t.begin() + 2, T(IntOrString(7)));
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 8f2871a54f..73e7abeb8c 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -72,7 +72,9 @@ private slots:
void defaultConstructor_int() { defaultConstructor<int>(); }
void defaultConstructor_QString() { defaultConstructor<QString>(); }
void append();
+#if QT_DEPRECATED_SINCE(6, 3)
void prepend();
+#endif
void emplace();
void move_int_1() { move_int<1>(); }
void move_int_2() { move_int<2>(); }
@@ -169,6 +171,9 @@ void tst_QVarLengthArray::append()
v2.append(5);
}
+#if QT_DEPRECATED_SINCE(6, 3)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
void tst_QVarLengthArray::prepend()
{
QVarLengthArray<QString, 2> v;
@@ -187,6 +192,8 @@ void tst_QVarLengthArray::prepend()
v.prepend(v.back());
QCOMPARE(v.front(), v.back());
}
+QT_WARNING_POP
+#endif // QT_DEPRECATED_SINCE(6, 3)
void tst_QVarLengthArray::emplace()
{
@@ -1339,7 +1346,7 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::liveCount, 6);
QCOMPARE(MyBase::movedCount, 2);
- vec.prepend(std::move(m1));
+ vec.insert(vec.cbegin(), std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
@@ -1411,7 +1418,7 @@ void tst_QVarLengthArray::nonCopyable()
QVERIFY(!val4);
QVERIFY(ptr3 == vec.at(0).get());
QVERIFY(ptr4 == vec.at(1).get());
- vec.prepend(std::move(val1));
+ vec.insert(vec.cbegin(), std::move(val1));
QVERIFY(!val1);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr3 == vec.at(1).get());