diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 46 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 23 | ||||
-rw-r--r-- | src/corelib/tools/qlocale_tools.cpp | 10 | ||||
-rw-r--r-- | src/corelib/tools/qlocale_tools_p.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qregexp.h | 5 | ||||
-rw-r--r-- | src/corelib/tools/qringbuffer.cpp | 89 | ||||
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 11 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qsharedpointer_impl.h | 42 | ||||
-rw-r--r-- | src/corelib/tools/qsimd_p.h | 1 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 20 | ||||
-rw-r--r-- | src/corelib/tools/qversionnumber.h | 2 |
13 files changed, 197 insertions, 66 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index a9f361c205..c223c9de6c 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -1713,6 +1713,14 @@ QByteArray &QByteArray::prepend(const char *str, int len) return *this; } +/*! \fn QByteArray &QByteArray::prepend(int count, char ch) + + \overload + \since 5.7 + + Prepends \a count copies of character \a ch to this byte array. +*/ + /*! \overload @@ -1825,6 +1833,17 @@ QByteArray &QByteArray::append(const char *str, int len) return *this; } +/*! \fn QByteArray &QByteArray::append(int count, char ch) + + \overload + \since 5.7 + + Appends \a count copies of character \a ch to this byte + array and returns a reference to this byte array. + + If \a count is negative or zero nothing is appended to the byte array. +*/ + /*! \overload @@ -1941,6 +1960,33 @@ QByteArray &QByteArray::insert(int i, char ch) return qbytearray_insert(this, i, &ch, 1); } +/*! \fn QByteArray &QByteArray::insert(int i, int count, char ch) + + \overload + \since 5.7 + + Inserts \a count copies of character \a ch at index position \a i in the + byte array. + + If \a i is greater than size(), the array is first extended using resize(). +*/ + +QByteArray &QByteArray::insert(int i, int count, char ch) +{ + if (i < 0 || count <= 0) + return *this; + + int oldsize = size(); + resize(qMax(i, oldsize) + count); + char *dst = d->data(); + if (i > oldsize) + ::memset(dst + oldsize, 0x20, i - oldsize); + else if (i < oldsize) + ::memmove(dst + i + count, dst + i, oldsize - i); + ::memset(dst + i, ch, count); + return *this; +} + /*! Removes \a len bytes from the array, starting at index position \a pos, and returns a reference to the array. diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index f0032227e8..6c79a603d3 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -255,21 +255,21 @@ public: # define Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT_pushed # endif - QByteArray toLower() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toLower() const & Q_REQUIRED_RESULT { return toLower_helper(*this); } - QByteArray toLower() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toLower() && Q_REQUIRED_RESULT { return toLower_helper(*this); } - QByteArray toUpper() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toUpper() const & Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QByteArray toUpper() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray toUpper() && Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QByteArray trimmed() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray trimmed() const & Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QByteArray trimmed() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray trimmed() && Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QByteArray simplified() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray simplified() const & Q_REQUIRED_RESULT { return simplified_helper(*this); } - QByteArray simplified() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QByteArray simplified() && Q_REQUIRED_RESULT { return simplified_helper(*this); } # ifdef Q_REQUIRED_RESULT_pushed # pragma pop_macro("Q_REQUIRED_RESULT") @@ -285,14 +285,17 @@ public: QByteArray rightJustified(int width, char fill = ' ', bool truncate = false) const Q_REQUIRED_RESULT; QByteArray &prepend(char c); + QByteArray &prepend(int count, char c); QByteArray &prepend(const char *s); QByteArray &prepend(const char *s, int len); QByteArray &prepend(const QByteArray &a); QByteArray &append(char c); + QByteArray &append(int count, char c); QByteArray &append(const char *s); QByteArray &append(const char *s, int len); QByteArray &append(const QByteArray &a); QByteArray &insert(int i, char c); + QByteArray &insert(int i, int count, char c); QByteArray &insert(int i, const char *s); QByteArray &insert(int i, const char *s, int len); QByteArray &insert(int i, const QByteArray &a); @@ -568,6 +571,10 @@ inline QByteArray::const_iterator QByteArray::cend() const { return d->data() + d->size; } inline QByteArray::const_iterator QByteArray::constEnd() const { return d->data() + d->size; } +inline QByteArray &QByteArray::append(int n, char ch) +{ return insert(d->size, n, ch); } +inline QByteArray &QByteArray::prepend(int n, char ch) +{ return insert(0, n, ch); } inline QByteArray &QByteArray::operator+=(char c) { return append(c); } inline QByteArray &QByteArray::operator+=(const char *s) diff --git a/src/corelib/tools/qlocale_tools.cpp b/src/corelib/tools/qlocale_tools.cpp index 03b911c4b3..dd58e7ff9f 100644 --- a/src/corelib/tools/qlocale_tools.cpp +++ b/src/corelib/tools/qlocale_tools.cpp @@ -2614,4 +2614,14 @@ static char *_qdtoa( NEEDS_VOLATILE double d, int mode, int ndigits, int *decpt, return s0; } +QString qdtoa(qreal d, int *decpt, int *sign) +{ + char *result = 0; + char *constResult = 0; + constResult = qdtoa(d, 0, 0, decpt, sign, 0, &result); + const QString ret(QString::fromLatin1(result ? result : constResult)); + free(result); + return ret; +} + QT_END_NAMESPACE diff --git a/src/corelib/tools/qlocale_tools_p.h b/src/corelib/tools/qlocale_tools_p.h index 03f35209b4..516a9fd05b 100644 --- a/src/corelib/tools/qlocale_tools_p.h +++ b/src/corelib/tools/qlocale_tools_p.h @@ -68,6 +68,7 @@ QT_BEGIN_NAMESPACE QString qulltoa(qulonglong l, int base, const QChar _zero); QString qlltoa(qlonglong l, int base, const QChar zero); +Q_CORE_EXPORT QString qdtoa(qreal d, int *decpt, int *sign); enum PrecisionMode { PMDecimalDigits = 0x01, diff --git a/src/corelib/tools/qregexp.h b/src/corelib/tools/qregexp.h index f384e6c51f..9c68c194e0 100644 --- a/src/corelib/tools/qregexp.h +++ b/src/corelib/tools/qregexp.h @@ -68,10 +68,9 @@ public: ~QRegExp(); QRegExp &operator=(const QRegExp &rx); #ifdef Q_COMPILER_RVALUE_REFS - inline QRegExp &operator=(QRegExp &&other) - { qSwap(priv,other.priv); return *this; } + QRegExp &operator=(QRegExp &&other) Q_DECL_NOTHROW { swap(other); return *this; } #endif - inline void swap(QRegExp &other) { qSwap(priv, other.priv); } + void swap(QRegExp &other) Q_DECL_NOTHROW { qSwap(priv, other.priv); } bool operator==(const QRegExp &rx) const; inline bool operator!=(const QRegExp &rx) const { return !operator==(rx); } diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp index 85cfdaf129..e9b655c01e 100644 --- a/src/corelib/tools/qringbuffer.cpp +++ b/src/corelib/tools/qringbuffer.cpp @@ -65,6 +65,8 @@ const char *QRingBuffer::readPointerAtPosition(qint64 pos, qint64 &length) const void QRingBuffer::free(qint64 bytes) { + Q_ASSERT(bytes <= bufferSize); + while (bytes > 0) { const qint64 blockSize = buffers.first().size() - head; @@ -100,20 +102,25 @@ char *QRingBuffer::reserve(qint64 bytes) if (bytes <= 0 || bytes >= MaxByteArraySize) return 0; - const qint64 newSize = bytes + tail; - // if need buffer reallocation - if (newSize > buffers.last().size()) { - if (newSize > buffers.last().capacity() && (tail >= basicBlockSize - || newSize >= MaxByteArraySize)) { - // shrink this buffer to its current size - buffers.last().resize(tail); - - // create a new QByteArray - buffers.append(QByteArray()); - ++tailBuffer; - tail = 0; + if (buffers.isEmpty()) { + buffers.append(QByteArray()); + buffers.first().resize(qMax(basicBlockSize, int(bytes))); + } else { + const qint64 newSize = bytes + tail; + // if need buffer reallocation + if (newSize > buffers.last().size()) { + if (newSize > buffers.last().capacity() && (tail >= basicBlockSize + || newSize >= MaxByteArraySize)) { + // shrink this buffer to its current size + buffers.last().resize(tail); + + // create a new QByteArray + buffers.append(QByteArray()); + ++tailBuffer; + tail = 0; + } + buffers.last().resize(qMax(basicBlockSize, tail + int(bytes))); } - buffers.last().resize(qMax(basicBlockSize, tail + int(bytes))); } char *writePtr = buffers.last().data() + tail; @@ -134,9 +141,13 @@ char *QRingBuffer::reserveFront(qint64 bytes) return 0; if (head < bytes) { - buffers.first().remove(0, head); - if (tailBuffer == 0) - tail -= head; + if (buffers.isEmpty()) { + buffers.append(QByteArray()); + } else { + buffers.first().remove(0, head); + if (tailBuffer == 0) + tail -= head; + } head = qMax(basicBlockSize, int(bytes)); if (bufferSize == 0) { @@ -155,6 +166,8 @@ char *QRingBuffer::reserveFront(qint64 bytes) void QRingBuffer::chop(qint64 bytes) { + Q_ASSERT(bytes <= bufferSize); + while (bytes > 0) { if (tailBuffer == 0 || tail > bytes) { // keep a single block around if it does not exceed @@ -185,6 +198,9 @@ void QRingBuffer::chop(qint64 bytes) void QRingBuffer::clear() { + if (buffers.isEmpty()) + return; + buffers.erase(buffers.begin() + 1, buffers.end()); buffers.first().clear(); @@ -193,20 +209,32 @@ void QRingBuffer::clear() bufferSize = 0; } -qint64 QRingBuffer::indexOf(char c, qint64 maxLength) const +qint64 QRingBuffer::indexOf(char c, qint64 maxLength, qint64 pos) const { - qint64 index = 0; - qint64 j = head; - for (int i = 0; index < maxLength && i < buffers.size(); ++i) { - const char *ptr = buffers[i].constData() + j; - j = qMin(index + (i == tailBuffer ? tail : buffers[i].size()) - j, maxLength); - - while (index < j) { - if (*ptr++ == c) - return index; - ++index; + if (maxLength <= 0 || pos < 0) + return -1; + + qint64 index = -(pos + head); + for (int i = 0; i < buffers.size(); ++i) { + const qint64 nextBlockIndex = qMin(index + (i == tailBuffer ? tail : buffers[i].size()), + maxLength); + + if (nextBlockIndex > 0) { + const char *ptr = buffers[i].constData(); + if (index < 0) { + ptr -= index; + index = 0; + } + + const char *findPtr = reinterpret_cast<const char *>(memchr(ptr, c, + nextBlockIndex - index)); + if (findPtr) + return qint64(findPtr - ptr) + index + pos; + + if (nextBlockIndex == maxLength) + return -1; } - j = 0; + index = nextBlockIndex; } return -1; } @@ -288,7 +316,10 @@ qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const void QRingBuffer::append(const QByteArray &qba) { if (tail == 0) { - buffers.last() = qba; + if (buffers.isEmpty()) + buffers.append(qba); + else + buffers.last() = qba; } else { buffers.last().resize(tail); buffers.append(qba); diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 68509a6a80..96c4f9acb6 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -54,9 +54,7 @@ class QRingBuffer { public: explicit inline QRingBuffer(int growth = 4096) : - head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { - buffers.append(QByteArray()); - } + head(0), tail(0), tailBuffer(0), basicBlockSize(growth), bufferSize(0) { } inline qint64 nextDataBlockSize() const { return (tailBuffer == 0 ? tail : buffers.first().size()) - head; @@ -114,14 +112,17 @@ public: Q_CORE_EXPORT void clear(); inline qint64 indexOf(char c) const { return indexOf(c, size()); } - Q_CORE_EXPORT qint64 indexOf(char c, qint64 maxLength) const; + Q_CORE_EXPORT qint64 indexOf(char c, qint64 maxLength, qint64 pos = 0) const; Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength); Q_CORE_EXPORT QByteArray read(); Q_CORE_EXPORT qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const; Q_CORE_EXPORT void append(const QByteArray &qba); inline qint64 skip(qint64 length) { - return read(0, length); + qint64 bytesToSkip = qMin(length, bufferSize); + + free(bytesToSkip); + return bytesToSkip; } Q_CORE_EXPORT qint64 readLine(char *data, qint64 maxLength); diff --git a/src/corelib/tools/qsharedpointer.cpp b/src/corelib/tools/qsharedpointer.cpp index 86f4c6a268..4d30396cb6 100644 --- a/src/corelib/tools/qsharedpointer.cpp +++ b/src/corelib/tools/qsharedpointer.cpp @@ -1292,6 +1292,17 @@ compile. Use qSharedPointerConstCast to cast away the constness. */ +/*! + \fn QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) + \relates QSharedPointer + \since 5.7 + + Writes the pointer tracked by \a ptr into the debug object \a debug for + debugging purposes. + + \sa {Debugging Techniques} +*/ + #include <qset.h> #include <qmutex.h> diff --git a/src/corelib/tools/qsharedpointer.h b/src/corelib/tools/qsharedpointer.h index 279ec36a28..56e13d500f 100644 --- a/src/corelib/tools/qsharedpointer.h +++ b/src/corelib/tools/qsharedpointer.h @@ -153,6 +153,8 @@ template <class X, class T> QSharedPointer<X> qSharedPointerObjectCast(const QWe template <class X, class T> QWeakPointer<X> qWeakPointerCast(const QWeakPointer<T> &src); +template <class T> QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr); + QT_END_NAMESPACE #endif // Q_QDOC diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 1323dd6b1c..ace6c5d093 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -55,6 +55,7 @@ QT_END_NAMESPACE #include <new> #include <QtCore/qatomic.h> #include <QtCore/qobject.h> // for qobject_cast +#include <QtCore/qdebug.h> #if QT_DEPRECATED_SINCE(5, 5) #include <QtCore/qhash.h> #endif @@ -305,7 +306,7 @@ public: inline T &operator*() const { return *data(); } inline T *operator->() const { return data(); } - QSharedPointer() : value(Q_NULLPTR), d(Q_NULLPTR) { } + QSharedPointer() Q_DECL_NOTHROW : value(Q_NULLPTR), d(Q_NULLPTR) {} ~QSharedPointer() { deref(); } inline explicit QSharedPointer(T *ptr) : value(ptr) // noexcept @@ -315,22 +316,22 @@ public: inline QSharedPointer(T *ptr, Deleter deleter) : value(ptr) // throws { internalConstruct(ptr, deleter); } - inline QSharedPointer(const QSharedPointer &other) : value(other.value), d(other.d) + QSharedPointer(const QSharedPointer &other) Q_DECL_NOTHROW : value(other.value), d(other.d) { if (d) ref(); } - inline QSharedPointer &operator=(const QSharedPointer &other) + QSharedPointer &operator=(const QSharedPointer &other) Q_DECL_NOTHROW { QSharedPointer copy(other); swap(copy); return *this; } #ifdef Q_COMPILER_RVALUE_REFS - inline QSharedPointer(QSharedPointer &&other) + QSharedPointer(QSharedPointer &&other) Q_DECL_NOTHROW : value(other.value), d(other.d) { other.d = Q_NULLPTR; other.value = Q_NULLPTR; } - inline QSharedPointer &operator=(QSharedPointer &&other) + QSharedPointer &operator=(QSharedPointer &&other) Q_DECL_NOTHROW { QSharedPointer moved(std::move(other)); swap(moved); @@ -596,7 +597,7 @@ public: inline bool operator !() const { return isNull(); } inline T *data() const { return d == Q_NULLPTR || d->strongref.load() == 0 ? Q_NULLPTR : value; } - inline QWeakPointer() : d(Q_NULLPTR), value(Q_NULLPTR) { } + inline QWeakPointer() Q_DECL_NOTHROW : d(Q_NULLPTR), value(Q_NULLPTR) { } inline ~QWeakPointer() { if (d && !d->weakref.deref()) delete d; } #ifndef QT_NO_QOBJECT @@ -614,15 +615,26 @@ public: { return *this = QWeakPointer(ptr); } #endif - inline QWeakPointer(const QWeakPointer &o) : d(o.d), value(o.value) + QWeakPointer(const QWeakPointer &other) Q_DECL_NOTHROW : d(other.d), value(other.value) { if (d) d->weakref.ref(); } - inline QWeakPointer &operator=(const QWeakPointer &o) +#ifdef Q_COMPILER_RVALUE_REFS + QWeakPointer(QWeakPointer &&other) Q_DECL_NOTHROW + : d(other.d), value(other.value) { - internalSet(o.d, o.value); + other.d = Q_NULLPTR; + other.value = Q_NULLPTR; + } + QWeakPointer &operator=(QWeakPointer &&other) Q_DECL_NOTHROW + { QWeakPointer moved(std::move(other)); swap(moved); return *this; } +#endif + QWeakPointer &operator=(const QWeakPointer &other) Q_DECL_NOTHROW + { + QWeakPointer copy(other); + swap(copy); return *this; } - inline void swap(QWeakPointer &other) + void swap(QWeakPointer &other) Q_DECL_NOTHROW { qSwap(this->d, other.d); qSwap(this->value, other.value); @@ -858,6 +870,16 @@ inline void qSwap(QSharedPointer<T> &p1, QSharedPointer<T> &p2) p1.swap(p2); } +#ifndef QT_NO_DEBUG_STREAM +template <class T> +Q_INLINE_TEMPLATE QDebug operator<<(QDebug debug, const QSharedPointer<T> &ptr) +{ + QDebugStateSaver saver(debug); + debug.nospace() << "QSharedPointer(" << ptr.data() << ")"; + return debug; +} +#endif + QT_END_NAMESPACE namespace std { template <class T> diff --git a/src/corelib/tools/qsimd_p.h b/src/corelib/tools/qsimd_p.h index 1e8b3420cf..96f5419af6 100644 --- a/src/corelib/tools/qsimd_p.h +++ b/src/corelib/tools/qsimd_p.h @@ -73,6 +73,7 @@ * SSE4_2 | x86 | I & C | I & C | I only | * AVX | x86 | I & C | I & C | I & C | * AVX2 | x86 | I & C | I & C | I only | + * AVX512xx | x86 | I & C | I & C | I only | * I = intrinsics; C = code generation * * Code can use the following constructs to determine compiler support & status: diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index d21708efb9..ba07259e77 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -387,25 +387,25 @@ public: # define Q_REQUIRED_RESULT # define Q_REQUIRED_RESULT_pushed # endif - QString toLower() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toLower() const & Q_REQUIRED_RESULT { return toLower_helper(*this); } - QString toLower() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toLower() && Q_REQUIRED_RESULT { return toLower_helper(*this); } - QString toUpper() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toUpper() const & Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QString toUpper() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toUpper() && Q_REQUIRED_RESULT { return toUpper_helper(*this); } - QString toCaseFolded() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toCaseFolded() const & Q_REQUIRED_RESULT { return toCaseFolded_helper(*this); } - QString toCaseFolded() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString toCaseFolded() && Q_REQUIRED_RESULT { return toCaseFolded_helper(*this); } - QString trimmed() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString trimmed() const & Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QString trimmed() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString trimmed() && Q_REQUIRED_RESULT { return trimmed_helper(*this); } - QString simplified() const & Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString simplified() const & Q_REQUIRED_RESULT { return simplified_helper(*this); } - QString simplified() && Q_REQUIRED_RESULT + Q_ALWAYS_INLINE QString simplified() && Q_REQUIRED_RESULT { return simplified_helper(*this); } # ifdef Q_REQUIRED_RESULT_pushed # pragma pop_macro("Q_REQUIRED_RESULT") diff --git a/src/corelib/tools/qversionnumber.h b/src/corelib/tools/qversionnumber.h index ebf1844f38..6a2718ca28 100644 --- a/src/corelib/tools/qversionnumber.h +++ b/src/corelib/tools/qversionnumber.h @@ -273,7 +273,7 @@ public: Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber commonPrefix(const QVersionNumber &v1, const QVersionNumber &v2) Q_REQUIRED_RESULT; Q_CORE_EXPORT QString toString() const Q_REQUIRED_RESULT; - Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = 0) Q_REQUIRED_RESULT; + Q_CORE_EXPORT static Q_DECL_PURE_FUNCTION QVersionNumber fromString(const QString &string, int *suffixIndex = Q_NULLPTR) Q_REQUIRED_RESULT; private: #ifndef QT_NO_DATASTREAM |