diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 17 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qbytearraylist.h | 3 | ||||
-rw-r--r-- | src/corelib/tools/qfreelist_p.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qiterator.h | 13 | ||||
-rw-r--r-- | src/corelib/tools/qlinkedlist.cpp | 6 | ||||
-rw-r--r-- | src/corelib/tools/qrect.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qregexp.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 27 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 62 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 22 | ||||
-rw-r--r-- | src/corelib/tools/qstringlist.cpp | 64 | ||||
-rw-r--r-- | src/corelib/tools/qstringlist.h | 54 | ||||
-rw-r--r-- | src/corelib/tools/qunicodetools.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvarlengtharray.h | 4 | ||||
-rw-r--r-- | src/corelib/tools/qvector.qdoc | 18 |
17 files changed, 247 insertions, 63 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 074072b987..dcd95924c1 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -323,8 +323,14 @@ struct QArrayDataPointerRef }()) \ /**/ +#ifdef Q_COMPILER_CONSTEXPR +#define Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type) Q_STATIC_ASSERT(std::is_literal_type<Type>::value) +#else +#define Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type) do {} while (0) +#endif + #define Q_ARRAY_LITERAL_IMPL(Type, ...) \ - Q_STATIC_ASSERT(std::is_literal_type<Type>::value); \ + Q_ARRAY_LITERAL_CHECK_LITERAL_TYPE(Type); \ \ /* Portable compile-time array size computation */ \ Q_CONSTEXPR Type data[] = { __VA_ARGS__ }; Q_UNUSED(data); \ diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index c25d39461f..ecbb4743af 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -943,6 +943,23 @@ QByteArray qUncompress(const uchar* data, int nbytes) and QByteArray() compares equal to QByteArray(""). We recommend that you always use isEmpty() and avoid isNull(). + \section1 Maximum size and out-of-memory conditions + + The current version of QByteArray is limited to just under 2 GB (2^31 + bytes) in size. The exact value is architecture-dependent, since it depends + on the overhead required for managing the data block, but is no more than + 32 bytes. Raw data blocks are also limited by the use of \c int type in the + current version to 2 GB minus 1 byte. + + In case memory allocation fails, QByteArray will throw a \c std::bad_alloc + exception. Out of memory conditions in the Qt containers are the only case + where Qt will throw exceptions. + + Note that the operating system may impose further limits on applications + holding a lot of allocated memory, especially large, contiguous blocks. + Such considerations, the configuration of such behavior or any mitigation + are outside the scope of the QByteArray API. + \section1 Notes on Locale \section2 Number-String Conversions diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index a81051d309..7c571706d8 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -548,7 +548,7 @@ class #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) Q_CORE_EXPORT #endif -QByteRef { +QByteRef { // ### Qt 7: remove QByteArray &a; int i; inline QByteRef(QByteArray &array, int idx) diff --git a/src/corelib/tools/qbytearraylist.h b/src/corelib/tools/qbytearraylist.h index 1261e1757c..0250b649b8 100644 --- a/src/corelib/tools/qbytearraylist.h +++ b/src/corelib/tools/qbytearraylist.h @@ -48,8 +48,11 @@ QT_BEGIN_NAMESPACE +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) typedef QListIterator<QByteArray> QByteArrayListIterator; typedef QMutableListIterator<QByteArray> QMutableByteArrayListIterator; +#endif + #ifndef Q_CLANG_QDOC typedef QList<QByteArray> QByteArrayList; diff --git a/src/corelib/tools/qfreelist_p.h b/src/corelib/tools/qfreelist_p.h index dcaf5688dc..5ba23b344b 100644 --- a/src/corelib/tools/qfreelist_p.h +++ b/src/corelib/tools/qfreelist_p.h @@ -218,7 +218,7 @@ template <typename T, typename ConstantsType> inline QFreeList<T, ConstantsType>::~QFreeList() { for (int i = 0; i < ConstantsType::BlockCount; ++i) - delete [] _v[i].loadRelaxed(); + delete [] _v[i].loadAcquire(); } template <typename T, typename ConstantsType> diff --git a/src/corelib/tools/qiterator.h b/src/corelib/tools/qiterator.h index 82212c3eb5..84a0e116ca 100644 --- a/src/corelib/tools/qiterator.h +++ b/src/corelib/tools/qiterator.h @@ -44,6 +44,8 @@ QT_BEGIN_NAMESPACE +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) + #define Q_DECLARE_SEQUENTIAL_ITERATOR(C) \ \ template <class T> \ @@ -115,11 +117,11 @@ template <class Key, class T> \ class Q##C##Iterator \ { \ typedef typename Q##C<Key,T>::const_iterator const_iterator; \ - typedef const_iterator Item; \ Q##C<Key,T> c; \ const_iterator i, n; \ inline bool item_exists() const { return n != c.constEnd(); } \ public: \ + typedef const_iterator Item; \ inline Q##C##Iterator(const Q##C<Key,T> &container) \ : c(container), i(c.constBegin()), n(c.constEnd()) {} \ inline Q##C##Iterator &operator=(const Q##C<Key,T> &container) \ @@ -148,11 +150,11 @@ class QMutable##C##Iterator \ { \ typedef typename Q##C<Key,T>::iterator iterator; \ typedef typename Q##C<Key,T>::const_iterator const_iterator; \ - typedef iterator Item; \ Q##C<Key,T> *c; \ iterator i, n; \ inline bool item_exists() const { return const_iterator(n) != c->constEnd(); } \ public: \ + typedef iterator Item; \ inline QMutable##C##Iterator(Q##C<Key,T> &container) \ : c(&container) \ { i = c->begin(); n = c->end(); } \ @@ -179,6 +181,13 @@ public: \ n = c->end(); return false; } \ }; +#else // QT_NO_JAVA_STYLE_ITERATORS +#define Q_DECLARE_SEQUENTIAL_ITERATOR(C) +#define Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(C) +#define Q_DECLARE_ASSOCIATIVE_ITERATOR(C) +#define Q_DECLARE_MUTABLE_ASSOCIATIVE_ITERATOR(C) +#endif // QT_NO_JAVA_STYLE_ITERATORS + template<typename Key, typename T, class Iterator> class QKeyValueIterator { diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp index c0450f5cd8..d239fe0ef4 100644 --- a/src/corelib/tools/qlinkedlist.cpp +++ b/src/corelib/tools/qlinkedlist.cpp @@ -742,8 +742,7 @@ const QLinkedListData QLinkedListData::shared_null = { \snippet code/src_corelib_tools_qlinkedlist.cpp 7 STL-style iterators can be used as arguments to \l{generic - algorithms}. For example, here's how to find an item in the list - using the qFind() algorithm: + algorithms}. For example, here's how to find an item in the list: \snippet code/src_corelib_tools_qlinkedlist.cpp 8 @@ -987,8 +986,7 @@ const QLinkedListData QLinkedListData::shared_null = { \snippet code/src_corelib_tools_qlinkedlist.cpp 14 STL-style iterators can be used as arguments to \l{generic - algorithms}. For example, here's how to find an item in the list - using the qFind() algorithm: + algorithms}. For example, here's how to find an item in the list: \snippet code/src_corelib_tools_qlinkedlist.cpp 15 diff --git a/src/corelib/tools/qrect.cpp b/src/corelib/tools/qrect.cpp index d622f92530..cd20102a2b 100644 --- a/src/corelib/tools/qrect.cpp +++ b/src/corelib/tools/qrect.cpp @@ -1194,7 +1194,7 @@ bool QRect::intersects(const QRect &r) const noexcept \fn QRect operator-(const QRect &lhs, const QMargins &rhs) \relates QRect - Returns the \a lhs rectangle shrunken by the \a rhs margins. + Returns the \a lhs rectangle shrunk by the \a rhs margins. \since 5.3 */ @@ -2417,7 +2417,7 @@ QRect QRectF::toAlignedRect() const noexcept \relates QRectF \since 5.3 - Returns the \a lhs rectangle grown by the \a rhs margins. + Returns the \a lhs rectangle shrunk by the \a rhs margins. */ /*! diff --git a/src/corelib/tools/qregexp.cpp b/src/corelib/tools/qregexp.cpp index 128df84053..dd38ba0360 100644 --- a/src/corelib/tools/qregexp.cpp +++ b/src/corelib/tools/qregexp.cpp @@ -1420,7 +1420,7 @@ void QRegExpMatchState::match(const QChar *str0, int len0, int pos0, #ifndef QT_NO_REGEXP_OPTIM if (eng->trivial && !oneTest) { - // ### Qt6: qsize + // ### Qt6: qsizetype pos = int(QtPrivate::findString(QStringView(str0, len0), pos0, QStringView(eng->goodStr.unicode(), eng->goodStr.length()), eng->cs)); matchLen = eng->goodStr.length(); matched = (pos != -1); diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 83e574bf1c..19d6982133 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -284,11 +284,9 @@ Q_INLINE_TEMPLATE void QSet<T>::reserve(int asize) { q_hash.reserve(asize); } template <class T> Q_INLINE_TEMPLATE QSet<T> &QSet<T>::unite(const QSet<T> &other) { - QSet<T> copy(other); - typename QSet<T>::const_iterator i = copy.constEnd(); - while (i != copy.constBegin()) { - --i; - insert(*i); + if (!q_hash.isSharedWith(other.q_hash)) { + for (const T &e : other) + insert(e); } return *this; } @@ -306,11 +304,9 @@ Q_INLINE_TEMPLATE QSet<T> &QSet<T>::intersect(const QSet<T> &other) copy2 = *this; *this = copy1; } - typename QSet<T>::const_iterator i = copy1.constEnd(); - while (i != copy1.constBegin()) { - --i; - if (!copy2.contains(*i)) - remove(*i); + for (const auto &e : qAsConst(copy1)) { + if (!copy2.contains(e)) + remove(e); } return *this; } @@ -346,14 +342,11 @@ Q_INLINE_TEMPLATE bool QSet<T>::intersects(const QSet<T> &other) const template <class T> Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other) { - if (&other == this) { + if (q_hash.isSharedWith(other.q_hash)) { clear(); } else { - auto i = other.constEnd(); - while (i != other.constBegin()) { - --i; - remove(*i); - } + for (const auto &e : other) + remove(e); } return *this; } @@ -409,6 +402,7 @@ QList<T> QList<T>::fromSet(const QSet<T> &set) Q_DECLARE_SEQUENTIAL_ITERATOR(Set) +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) template <typename T> class QMutableSetIterator { @@ -440,6 +434,7 @@ public: { while (c->constBegin() != i) if (*(n = --i) == t) return true; n = c->end(); return false; } }; +#endif // QT_NO_JAVA_STYLE_ITERATORS QT_END_NAMESPACE diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index f9a9fcfe91..47db97cdfc 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1739,6 +1739,24 @@ const QString::Null QString::null = { }; and the \c{'+'} will automatically be performed as the \c{QStringBuilder} \c{'%'} everywhere. + \section1 Maximum size and out-of-memory conditions + + The current version of QString is limited to just under 2 GB (2^31 bytes) + in size. The exact value is architecture-dependent, since it depends on the + overhead required for managing the data block, but is no more than 32 + bytes. Raw data blocks are also limited by the use of \c int type in the + current version to 2 GB minus 1 byte. Since QString uses two bytes per + character, that translates to just under 2^30 characters in one QString. + + In case memory allocation fails, QString will throw a \c std::bad_alloc + exception. Out of memory conditions in the Qt containers are the only case + where Qt will throw exceptions. + + Note that the operating system may impose further limits on applications + holding a lot of allocated memory, especially large, contiguous blocks. + Such considerations, the configuration of such behavior or any mitigation + are outside the scope of the Qt API. + \sa fromRawData(), QChar, QLatin1String, QByteArray, QStringRef */ @@ -3701,7 +3719,7 @@ bool QString::operator>(QLatin1String other) const noexcept */ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } #endif // QT_STRINGVIEW_LEVEL < 2 @@ -3745,7 +3763,7 @@ int QString::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); } @@ -3758,7 +3776,7 @@ int QString::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const */ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qFindChar(QStringView(unicode(), length()), ch, from, cs)); } @@ -3777,7 +3795,7 @@ int QString::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } @@ -3799,7 +3817,7 @@ int QString::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) co */ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } @@ -3826,7 +3844,7 @@ int QString::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) c */ int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } @@ -3838,7 +3856,7 @@ int QString::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) co */ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qLastIndexOf(*this, ch, from, cs)); } @@ -3860,7 +3878,7 @@ int QString::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QString::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } #endif // QT_STRINGVIEW_LEVEL < 2 @@ -4192,7 +4210,7 @@ QString &QString::replace(const QRegularExpression &re, const QString &after) int QString::count(const QString &str, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } @@ -4209,7 +4227,7 @@ int QString::count(const QString &str, Qt::CaseSensitivity cs) const int QString::count(QChar ch, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), ch, cs)); } @@ -4226,7 +4244,7 @@ int QString::count(QChar ch, Qt::CaseSensitivity cs) const */ int QString::count(const QStringRef &str, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } @@ -11172,7 +11190,7 @@ QStringRef QString::midRef(int position, int n) const */ int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), length()), from, QStringView(str.unicode(), str.length()), cs)); } #endif // QT_STRINGVIEW_LEVEL < 2 @@ -11207,7 +11225,7 @@ int QStringRef::indexOf(const QString &str, int from, Qt::CaseSensitivity cs) co */ int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qFindChar(QStringView(unicode(), length()), ch, from, cs)); } @@ -11228,7 +11246,7 @@ int QStringRef::indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), size()), from, str, cs)); } @@ -11249,7 +11267,7 @@ int QStringRef::indexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) con */ int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::findString(QStringView(unicode(), size()), from, QStringView(str.unicode(), str.size()), cs)); } #endif // QT_STRINGVIEW_LEVEL < 2 @@ -11270,7 +11288,7 @@ int QStringRef::indexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) */ int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } @@ -11285,7 +11303,7 @@ int QStringRef::lastIndexOf(const QString &str, int from, Qt::CaseSensitivity cs */ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qLastIndexOf(*this, ch, from, cs)); } @@ -11306,7 +11324,7 @@ int QStringRef::lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const */ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } @@ -11327,7 +11345,7 @@ int QStringRef::lastIndexOf(QLatin1String str, int from, Qt::CaseSensitivity cs) */ int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(QtPrivate::lastIndexOf(*this, from, str, cs)); } @@ -11360,7 +11378,7 @@ int QStringRef::lastIndexOf(const QStringRef &str, int from, Qt::CaseSensitivity */ int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } @@ -11378,7 +11396,7 @@ int QStringRef::count(const QString &str, Qt::CaseSensitivity cs) const */ int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), ch, cs)); } @@ -11396,7 +11414,7 @@ int QStringRef::count(QChar ch, Qt::CaseSensitivity cs) const */ int QStringRef::count(const QStringRef &str, Qt::CaseSensitivity cs) const { - // ### Qt6: qsize + // ### Qt6: qsizetype return int(qt_string_count(QStringView(unicode(), size()), QStringView(str.unicode(), str.size()), cs)); } diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index b56b37edf3..6788e53057 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -135,11 +135,11 @@ public: { return QtPrivate::endsWith(*this, QStringView(&c, 1), cs); } Q_REQUIRED_RESULT int indexOf(QStringView s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype Q_REQUIRED_RESULT int indexOf(QLatin1String s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype Q_REQUIRED_RESULT inline int indexOf(QChar c, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, QStringView(&c, 1), cs)); } // ### Qt6: qsize + { return int(QtPrivate::findString(*this, from, QStringView(&c, 1), cs)); } // ### Qt6: qsizetype Q_REQUIRED_RESULT bool contains(QStringView s, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return indexOf(s, 0, cs) != -1; } @@ -149,11 +149,11 @@ public: { return indexOf(QStringView(&c, 1), 0, cs) != -1; } Q_REQUIRED_RESULT int lastIndexOf(QStringView s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype Q_REQUIRED_RESULT int lastIndexOf(QLatin1String s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype Q_REQUIRED_RESULT inline int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs)); } // ### Qt6: qsize + { return int(QtPrivate::lastIndexOf(*this, from, QStringView(&c, 1), cs)); } // ### Qt6: qsizetype using value_type = const char; using reference = value_type&; @@ -367,7 +367,7 @@ public: int indexOf(const QStringRef &s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif Q_REQUIRED_RESULT int indexOf(QStringView s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype int lastIndexOf(QChar c, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(QLatin1String s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_STRINGVIEW_LEVEL < 2 @@ -376,7 +376,7 @@ public: #endif Q_REQUIRED_RESULT int lastIndexOf(QStringView s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype inline bool contains(QChar c, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_STRINGVIEW_LEVEL < 2 @@ -1103,7 +1103,7 @@ class #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) Q_CORE_EXPORT #endif -QCharRef { +QCharRef { // ### Qt 7: remove QString &s; int i; inline QCharRef(QString &str, int idx) @@ -1555,7 +1555,7 @@ public: int indexOf(const QStringRef &str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #endif Q_REQUIRED_RESULT int indexOf(QStringView s, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::findString(*this, from, s, cs)); } // ### Qt6: qsizetype int indexOf(QChar ch, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int indexOf(QLatin1String str, int from = 0, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; #if QT_STRINGVIEW_LEVEL < 2 @@ -1565,7 +1565,7 @@ public: int lastIndexOf(QChar ch, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; int lastIndexOf(QLatin1String str, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; Q_REQUIRED_RESULT int lastIndexOf(QStringView s, int from = -1, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept - { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsize + { return int(QtPrivate::lastIndexOf(*this, from, s, cs)); } // ### Qt6: qsizetype #if QT_STRINGVIEW_LEVEL < 2 inline bool contains(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; diff --git a/src/corelib/tools/qstringlist.cpp b/src/corelib/tools/qstringlist.cpp index f6da7b1428..4bbe424ed2 100644 --- a/src/corelib/tools/qstringlist.cpp +++ b/src/corelib/tools/qstringlist.cpp @@ -283,6 +283,7 @@ void QtPrivate::QStringList_sort(QStringList *that, Qt::CaseSensitivity cs) } +#if QT_STRINGVIEW_LEVEL < 2 /*! \fn QStringList QStringList::filter(const QString &str, Qt::CaseSensitivity cs) const @@ -302,6 +303,26 @@ void QtPrivate::QStringList_sort(QStringList *that, Qt::CaseSensitivity cs) \sa contains() */ +#endif + +/*! + \fn QStringList QStringList::filter(QStringView str, Qt::CaseSensitivity cs) const + \overload + \since 5.14 +*/ +QStringList QtPrivate::QStringList_filter(const QStringList *that, QStringView str, + Qt::CaseSensitivity cs) +{ + QStringMatcher matcher(str, cs); + QStringList res; + for (int i = 0; i < that->size(); ++i) + if (matcher.indexIn(that->at(i)) != -1) + res << that->at(i); + return res; +} + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/// Not really needed anymore, but kept for binary compatibility QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs) { @@ -312,6 +333,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QString res << that->at(i); return res; } +#endif template<typename T> static bool stringList_contains(const QStringList &stringList, const T &str, Qt::CaseSensitivity cs) @@ -466,6 +488,7 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula } #endif // QT_CONFIG(regularexpression) +#if QT_STRINGVIEW_LEVEL < 2 /*! \fn QStringList &QStringList::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) @@ -481,12 +504,41 @@ QStringList QtPrivate::QStringList_filter(const QStringList *that, const QRegula \sa QString::replace() */ + +/*! + \fn QStringList &QStringList::replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs) + \overload + \since 5.14 +*/ + +/*! + \fn QStringList &QStringList::replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs) + \overload + \since 5.14 +*/ +#endif + +/*! + \fn QStringList &QStringList::replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs) + \overload + \since 5.14 +*/ +void QtPrivate::QStringList_replaceInStrings(QStringList *that, QStringView before, + QStringView after, Qt::CaseSensitivity cs) +{ + for (int i = 0; i < that->size(); ++i) + (*that)[i].replace(before.data(), before.length(), after.data(), after.length(), cs); +} + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/// Not really needed anymore, but kept for binary compatibility void QtPrivate::QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs) { for (int i = 0; i < that->size(); ++i) (*that)[i].replace(before, after, cs); } +#endif #ifndef QT_NO_REGEXP @@ -561,6 +613,7 @@ static int accumulatedSize(const QStringList &list, int seplen) return result; } +#if QT_STRINGVIEW_LEVEL < 2 /*! \fn QString QStringList::join(const QString &separator) const @@ -570,6 +623,7 @@ static int accumulatedSize(const QStringList &list, int seplen) \sa QString::split() */ +#endif /*! \fn QString QStringList::join(QChar separator) const @@ -615,6 +669,16 @@ QString QtPrivate::QStringList_join(const QStringList &list, QLatin1String sep) } /*! + \fn QString QStringList::join(QStringView separator) const + \overload + \since 5.14 +*/ +QString QtPrivate::QStringList_join(const QStringList *that, QStringView sep) +{ + return QStringList_join(that, sep.data(), sep.length()); +} + +/*! \fn QStringList QStringList::operator+(const QStringList &other) const Returns a string list that is the concatenation of this string diff --git a/src/corelib/tools/qstringlist.h b/src/corelib/tools/qstringlist.h index 3bb657069b..a464d443dc 100644 --- a/src/corelib/tools/qstringlist.h +++ b/src/corelib/tools/qstringlist.h @@ -54,8 +54,10 @@ QT_BEGIN_NAMESPACE class QRegExp; class QRegularExpression; +#if !defined(QT_NO_JAVA_STYLE_ITERATORS) typedef QListIterator<QString> QStringListIterator; typedef QMutableListIterator<QString> QMutableStringListIterator; +#endif class QStringList; @@ -73,12 +75,21 @@ public: inline void sort(Qt::CaseSensitivity cs = Qt::CaseSensitive); inline int removeDuplicates(); +#if QT_STRINGVIEW_LEVEL < 2 inline QString join(const QString &sep) const; +#endif + inline QString join(QStringView sep) const; inline QString join(QLatin1String sep) const; inline QString join(QChar sep) const; + inline QStringList filter(QStringView str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; + inline QStringList &replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive); +#if QT_STRINGVIEW_LEVEL < 2 inline QStringList filter(const QString &str, Qt::CaseSensitivity cs = Qt::CaseSensitive) const; inline QStringList &replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + inline QStringList &replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs = Qt::CaseSensitive); + inline QStringList &replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs = Qt::CaseSensitive); +#endif #ifndef QT_NO_REGEXP inline QStringList filter(const QRegExp &rx) const; @@ -163,18 +174,27 @@ inline const QStringList *QListSpecialMethods<QString>::self() const namespace QtPrivate { void Q_CORE_EXPORT QStringList_sort(QStringList *that, Qt::CaseSensitivity cs); int Q_CORE_EXPORT QStringList_removeDuplicates(QStringList *that); + QString Q_CORE_EXPORT QStringList_join(const QStringList *that, QStringView sep); QString Q_CORE_EXPORT QStringList_join(const QStringList *that, const QChar *sep, int seplen); Q_CORE_EXPORT QString QStringList_join(const QStringList &list, QLatin1String sep); + QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, QStringView str, + Qt::CaseSensitivity cs); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QStringList Q_CORE_EXPORT QStringList_filter(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); +#endif #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, const QString &str, Qt::CaseSensitivity cs); #endif bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QStringView str, Qt::CaseSensitivity cs); bool Q_CORE_EXPORT QStringList_contains(const QStringList *that, QLatin1String str, Qt::CaseSensitivity cs); + void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, QStringView before, QStringView after, + Qt::CaseSensitivity cs); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QString &before, const QString &after, Qt::CaseSensitivity cs); +#endif #ifndef QT_NO_REGEXP void Q_CORE_EXPORT QStringList_replaceInStrings(QStringList *that, const QRegExp &rx, const QString &after); @@ -203,10 +223,17 @@ inline int QListSpecialMethods<QString>::removeDuplicates() return QtPrivate::QStringList_removeDuplicates(self()); } +#if QT_STRINGVIEW_LEVEL < 2 inline QString QListSpecialMethods<QString>::join(const QString &sep) const { return QtPrivate::QStringList_join(self(), sep.constData(), sep.length()); } +#endif + +inline QString QListSpecialMethods<QString>::join(QStringView sep) const +{ + return QtPrivate::QStringList_join(self(), sep); +} QString QListSpecialMethods<QString>::join(QLatin1String sep) const { @@ -218,10 +245,17 @@ inline QString QListSpecialMethods<QString>::join(QChar sep) const return QtPrivate::QStringList_join(self(), &sep, 1); } +inline QStringList QListSpecialMethods<QString>::filter(QStringView str, Qt::CaseSensitivity cs) const +{ + return QtPrivate::QStringList_filter(self(), str, cs); +} + +#if QT_STRINGVIEW_LEVEL < 2 inline QStringList QListSpecialMethods<QString>::filter(const QString &str, Qt::CaseSensitivity cs) const { return QtPrivate::QStringList_filter(self(), str, cs); } +#endif #if QT_STRINGVIEW_LEVEL < 2 inline bool QStringList::contains(const QString &str, Qt::CaseSensitivity cs) const @@ -240,12 +274,32 @@ inline bool QStringList::contains(QStringView str, Qt::CaseSensitivity cs) const return QtPrivate::QStringList_contains(this, str, cs); } +inline QStringList &QListSpecialMethods<QString>::replaceInStrings(QStringView before, QStringView after, Qt::CaseSensitivity cs) +{ + QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); + return *self(); +} + +#if QT_STRINGVIEW_LEVEL < 2 inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QString &before, const QString &after, Qt::CaseSensitivity cs) { QtPrivate::QStringList_replaceInStrings(self(), before, after, cs); return *self(); } +inline QStringList &QListSpecialMethods<QString>::replaceInStrings(QStringView before, const QString &after, Qt::CaseSensitivity cs) +{ + QtPrivate::QStringList_replaceInStrings(self(), before, qToStringViewIgnoringNull(after), cs); + return *self(); +} + +inline QStringList &QListSpecialMethods<QString>::replaceInStrings(const QString &before, QStringView after, Qt::CaseSensitivity cs) +{ + QtPrivate::QStringList_replaceInStrings(self(), QStringView(before), after, cs); + return *self(); +} +#endif + inline QStringList operator+(const QList<QString> &one, const QStringList &other) { QStringList n = one; diff --git a/src/corelib/tools/qunicodetools.cpp b/src/corelib/tools/qunicodetools.cpp index d14118abf7..08e1146c59 100644 --- a/src/corelib/tools/qunicodetools.cpp +++ b/src/corelib/tools/qunicodetools.cpp @@ -327,7 +327,7 @@ static const uchar breakTable[BAfter + 1][QUnicodeTables::NumSentenceBreakClasse // Any CR LF Sep Extend Sp Lower Upper OLetter Numeric ATerm SContinue STerm Close { Initial, BAfterC, BAfter , BAfter , Initial, Initial, Lower , Upper , Initial, Initial, ATerm , Initial, STerm , Initial }, // Initial { Initial, BAfterC, BAfter , BAfter , Lower , Initial, Initial, Initial, Initial, Initial, LUATerm, Initial, STerm , Initial }, // Lower - { Initial, BAfterC, BAfter , BAfter , Upper , Initial, Initial, Upper , Initial, Initial, LUATerm, STerm , STerm , Initial }, // Upper + { Initial, BAfterC, BAfter , BAfter , Upper , Initial, Initial, Upper , Initial, Initial, LUATerm, Initial, STerm , Initial }, // Upper { Lookup , BAfterC, BAfter , BAfter , LUATerm, ACS , Initial, Upper , Break , Initial, ATerm , STerm , STerm , ATermC }, // LUATerm { Lookup , BAfterC, BAfter , BAfter , ATerm , ACS , Initial, Break , Break , Initial, ATerm , STerm , STerm , ATermC }, // ATerm diff --git a/src/corelib/tools/qvarlengtharray.h b/src/corelib/tools/qvarlengtharray.h index a49e0af687..ba65ae7ef2 100644 --- a/src/corelib/tools/qvarlengtharray.h +++ b/src/corelib/tools/qvarlengtharray.h @@ -61,7 +61,9 @@ template<class T, int Prealloc> class QVarLengthArray { public: - inline explicit QVarLengthArray(int size = 0); + QVarLengthArray() : QVarLengthArray(0) {} + + inline explicit QVarLengthArray(int size); inline QVarLengthArray(const QVarLengthArray<T, Prealloc> &other) : a(Prealloc), s(0), ptr(reinterpret_cast<T *>(array)) diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc index 4c442511ea..8765b7fbd6 100644 --- a/src/corelib/tools/qvector.qdoc +++ b/src/corelib/tools/qvector.qdoc @@ -173,6 +173,24 @@ For a detailed discussion comparing Qt containers with each other and with STL containers, see \l {Understand the Qt Containers}. + \section1 Maximum size and out-of-memory conditions + + The current version of QVector is limited to just under 2 GB (2^31 bytes) + in size. The exact value is architecture-dependent, since it depends on the + overhead required for managing the data block, but is no more than 32 + bytes. The number of elements that can be stored in a QVector is that size + divided by the size of each element. + + In case memory allocation fails, QVector will use the \l Q_CHECK_PTR macro, + which will throw a \c std::bad_alloc exception if the application is being + compiled with exception support. If exceptions are disabled, then running + out of memory is undefined behavior. + + Note that the operating system may impose further limits on applications + holding a lot of allocated memory, especially large, contiguous blocks. + Such considerations, the configuration of such behavior or any mitigation + are outside the scope of the Qt API. + \sa QVectorIterator, QMutableVectorIterator, QList, QLinkedList */ |