diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 7 | ||||
-rw-r--r-- | src/corelib/tools/qcollator.cpp | 22 | ||||
-rw-r--r-- | src/corelib/tools/qcommandlineparser.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qcontiguouscache.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qdatetimeparser.cpp | 14 | ||||
-rw-r--r-- | src/corelib/tools/qdatetimeparser_p.h | 3 | ||||
-rw-r--r-- | src/corelib/tools/qhash.h | 25 | ||||
-rw-r--r-- | src/corelib/tools/qlist.h | 10 | ||||
-rw-r--r-- | src/corelib/tools/qlocale_mac.mm | 14 | ||||
-rw-r--r-- | src/corelib/tools/qpair.qdoc | 54 | ||||
-rw-r--r-- | src/corelib/tools/qregularexpression.cpp | 20 | ||||
-rw-r--r-- | src/corelib/tools/qringbuffer.cpp | 309 | ||||
-rw-r--r-- | src/corelib/tools/qringbuffer_p.h | 266 | ||||
-rw-r--r-- | src/corelib/tools/qscopedpointer.cpp | 7 | ||||
-rw-r--r-- | src/corelib/tools/qset.h | 30 | ||||
-rw-r--r-- | src/corelib/tools/qset.qdoc | 25 | ||||
-rw-r--r-- | src/corelib/tools/qsimd.cpp | 4 | ||||
-rw-r--r-- | src/corelib/tools/qsize.h | 20 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 112 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/qvector.cpp | 22 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 2 | ||||
-rw-r--r-- | src/corelib/tools/tools.pri | 1 |
23 files changed, 656 insertions, 323 deletions
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index da5d00311a..36c1f42995 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -124,7 +124,7 @@ int qFindByteArray( int qAllocMore(int alloc, int extra) Q_DECL_NOTHROW { Q_ASSERT(alloc >= 0 && extra >= 0); - Q_ASSERT_X(uint(alloc) < QByteArray::MaxSize, "qAllocMore", "Requested size is too large!"); + Q_ASSERT_X(uint(alloc) <= QByteArray::MaxSize, "qAllocMore", "Requested size is too large!"); unsigned nalloc = qNextPowerOfTwo(alloc + extra); @@ -842,8 +842,9 @@ static inline char qToLower(char c) \internal \since 5.4 - The maximum size of a QByteArray, in bytes. Also applies to a the maximum - storage size of QString and QVector, though not the number of elements. + The maximum size of a QByteArray (including a '\0' terminator), in bytes. + Also applies to the maximum storage size of QString and QVector, though + not the number of elements. */ /*! diff --git a/src/corelib/tools/qcollator.cpp b/src/corelib/tools/qcollator.cpp index 9148ecf6fc..615b7a4e3e 100644 --- a/src/corelib/tools/qcollator.cpp +++ b/src/corelib/tools/qcollator.cpp @@ -87,7 +87,7 @@ QCollator::QCollator(const QCollator &other) } /*! - Destroys the collator. + Destructor for QCollator. */ QCollator::~QCollator() { @@ -109,8 +109,8 @@ QCollator &QCollator::operator=(const QCollator &other) return *this; } -/* - \fn void QCollator::QCollator(QCollator &&other) +/*! + \fn QCollator::QCollator(QCollator &&other) Move constructor. Moves from \a other into this collator. @@ -119,8 +119,8 @@ QCollator &QCollator::operator=(const QCollator &other) one of the assignment operators is undefined. */ -/* - \fn QCollator &QCollator::operator=(QCollator &&other) +/*! + \fn QCollator & QCollator::operator=(QCollator && other) Move-assigns from \a other to this collator. @@ -367,6 +367,12 @@ QCollatorSortKey& QCollatorSortKey::operator=(const QCollatorSortKey &other) } /*! + \fn QCollatorSortKey &QCollatorSortKey::operator=(QCollatorSortKey && other) + + Move-assigns \a other to this collator key. +*/ + +/*! \fn bool operator<(const QCollatorSortKey &lhs, const QCollatorSortKey &rhs) \relates QCollatorSortKey @@ -377,6 +383,12 @@ QCollatorSortKey& QCollatorSortKey::operator=(const QCollatorSortKey &other) */ /*! + \fn void QCollatorSortKey::swap(QCollatorSortKey & other) + + Swaps this collator key with \a other. +*/ + +/*! \fn int QCollatorSortKey::compare(const QCollatorSortKey &otherKey) const Compares the key to \a otherKey. Returns a negative value if the key diff --git a/src/corelib/tools/qcommandlineparser.cpp b/src/corelib/tools/qcommandlineparser.cpp index 7e49253f9b..4cc3a2c293 100644 --- a/src/corelib/tools/qcommandlineparser.cpp +++ b/src/corelib/tools/qcommandlineparser.cpp @@ -119,8 +119,8 @@ public: QStringList QCommandLineParserPrivate::aliases(const QString &optionName) const { - const NameHash_t::const_iterator it = nameHash.find(optionName); - if (it == nameHash.end()) { + const NameHash_t::const_iterator it = nameHash.constFind(optionName); + if (it == nameHash.cend()) { qWarning("QCommandLineParser: option not defined: \"%s\"", qPrintable(optionName)); return QStringList(); } @@ -847,8 +847,8 @@ QString QCommandLineParser::value(const QString &optionName) const QStringList QCommandLineParser::values(const QString &optionName) const { d->checkParsed("values"); - const NameHash_t::const_iterator it = d->nameHash.find(optionName); - if (it != d->nameHash.end()) { + const NameHash_t::const_iterator it = d->nameHash.constFind(optionName); + if (it != d->nameHash.cend()) { const int optionOffset = *it; QStringList values = d->optionValuesHash.value(optionOffset); if (values.isEmpty()) diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index fc4fb1e7cb..41d198f9bc 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -291,7 +291,7 @@ QContiguousCache<T> &QContiguousCache<T>::operator=(const QContiguousCache<T> &o { other.d->ref.ref(); if (!d->ref.deref()) - freeData(d); + freeData(p); d = other.d; if (!d->sharable) detach_helper(); diff --git a/src/corelib/tools/qdatetimeparser.cpp b/src/corelib/tools/qdatetimeparser.cpp index 255e9557e2..eaa695ef27 100644 --- a/src/corelib/tools/qdatetimeparser.cpp +++ b/src/corelib/tools/qdatetimeparser.cpp @@ -1362,11 +1362,11 @@ int QDateTimeParser::findDay(const QString &str1, int startDay, int sectionIndex \internal returns - 0 if str == QDateTimeEdit::tr("AM") - 1 if str == QDateTimeEdit::tr("PM") - 2 if str can become QDateTimeEdit::tr("AM") - 3 if str can become QDateTimeEdit::tr("PM") - 4 if str can become QDateTimeEdit::tr("PM") and can become QDateTimeEdit::tr("AM") + 0 if str == tr("AM") + 1 if str == tr("PM") + 2 if str can become tr("AM") + 3 if str can become tr("PM") + 4 if str can become tr("PM") and can become tr("AM") -1 can't become anything sensible */ @@ -1737,9 +1737,9 @@ QDateTime QDateTimeParser::getMaximum() const QString QDateTimeParser::getAmPmText(AmPm ap, Case cs) const { if (ap == AmText) { - return (cs == UpperCase ? QLatin1String("AM") : QLatin1String("am")); + return (cs == UpperCase ? tr("AM") : tr("am")); } else { - return (cs == UpperCase ? QLatin1String("PM") : QLatin1String("pm")); + return (cs == UpperCase ? tr("PM") : tr("pm")); } } diff --git a/src/corelib/tools/qdatetimeparser_p.h b/src/corelib/tools/qdatetimeparser_p.h index 55dc3bf7a0..9457e35ad5 100644 --- a/src/corelib/tools/qdatetimeparser_p.h +++ b/src/corelib/tools/qdatetimeparser_p.h @@ -54,7 +54,7 @@ # include "QtCore/qvariant.h" #endif #include "QtCore/qvector.h" - +#include "QtCore/qcoreapplication.h" #define QDATETIMEEDIT_TIME_MIN QTime(0, 0, 0, 0) #define QDATETIMEEDIT_TIME_MAX QTime(23, 59, 59, 999) @@ -72,6 +72,7 @@ QT_BEGIN_NAMESPACE class Q_CORE_EXPORT QDateTimeParser { + Q_DECLARE_TR_FUNCTIONS(QDateTimeParser) public: enum Context { FromString, diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index c4c8c8f3cc..2080a22e23 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -353,6 +353,7 @@ public: class const_iterator { friend class iterator; + friend class QSet<Key>; QHashData::Node *i; public: @@ -451,6 +452,7 @@ private: void detach_helper(); void freeData(QHashData *d); Node **findNode(const Key &key, uint *hp = 0) const; + Node **findNode(const Key &key, uint h) const; Node *createNode(uint h, const Key &key, const T &value, Node **nextNode); void deleteNode(Node *node); static void deleteNode2(QHashData::Node *node); @@ -846,17 +848,10 @@ Q_INLINE_TEMPLATE bool QHash<Key, T>::contains(const Key &akey) const } template <class Key, class T> -Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey, - uint *ahp) const +Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey, uint h) const { Node **node; - uint h = 0; - if (d->numBuckets || ahp) { - h = qHash(akey, d->seed); - if (ahp) - *ahp = h; - } if (d->numBuckets) { node = reinterpret_cast<Node **>(&d->buckets[h % d->numBuckets]); Q_ASSERT(*node == e || (*node)->next); @@ -869,6 +864,20 @@ Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(cons } template <class Key, class T> +Q_OUTOFLINE_TEMPLATE typename QHash<Key, T>::Node **QHash<Key, T>::findNode(const Key &akey, + uint *ahp) const +{ + uint h = 0; + + if (d->numBuckets || ahp) { + h = qHash(akey, d->seed); + if (ahp) + *ahp = h; + } + return findNode(akey, h); +} + +template <class Key, class T> Q_OUTOFLINE_TEMPLATE bool QHash<Key, T>::operator==(const QHash &other) const { if (size() != other.size()) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 1e002633df..e446a6625b 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -221,6 +221,11 @@ public: inline iterator() : i(0) {} inline iterator(Node *n) : i(n) {} +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + // can't remove it in Qt 5, since doing so would make the type trivial, + // which changes the way it's passed to functions by value. + inline iterator(const iterator &o): i(o.i){} +#endif inline T &operator*() const { return i->t(); } inline T *operator->() const { return &i->t(); } inline T &operator[](difference_type j) const { return i[j].t(); } @@ -268,6 +273,11 @@ public: inline const_iterator() : i(0) {} inline const_iterator(Node *n) : i(n) {} +#if QT_VERSION < QT_VERSION_CHECK(6,0,0) + // can't remove it in Qt 5, since doing so would make the type trivial, + // which changes the way it's passed to functions by value. + inline const_iterator(const const_iterator &o): i(o.i) {} +#endif #ifdef QT_STRICT_ITERATORS inline explicit const_iterator(const iterator &o): i(o.i) {} #else diff --git a/src/corelib/tools/qlocale_mac.mm b/src/corelib/tools/qlocale_mac.mm index 37a63a2ca4..c0818f07d7 100644 --- a/src/corelib/tools/qlocale_mac.mm +++ b/src/corelib/tools/qlocale_mac.mm @@ -44,18 +44,6 @@ QT_BEGIN_NAMESPACE -namespace { -class AutoReleasePool -{ -public: - AutoReleasePool(): pool([[NSAutoreleasePool alloc] init]) {} - ~AutoReleasePool() { [pool release]; } - -private: - NSAutoreleasePool *pool; -}; -} - /****************************************************************************** ** Wrappers for Mac locale system functions */ @@ -426,7 +414,7 @@ QLocale QSystemLocale::fallbackUiLocale() const QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const { - AutoReleasePool pool; + QMacAutoReleasePool pool; switch(type) { // case Name: // return getMacLocaleName(); diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index 48555ed6d1..4452d2f0b8 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -96,6 +96,30 @@ \sa qMakePair() */ +\fn void QPair::swap(QPair &other) + + \since 5.5 + Swaps this pair with \a other. + + Equivalent to + \code + qSwap(this->first, other.first); + qSwap(this->second, other.second); + \endcode + + Swap overloads are found in namespace \c std as well as via + argument-dependent lookup (ADL) in \c{T}'s namespace. +*/ + +/*! +\fn void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) + \overload + \relates QPair + \since 5.5 + + Swaps \a lhs with \a rhs. +*/ + /*! \fn QPair::QPair(const QPair<TT1, TT2> &p) \since 5.2 @@ -108,37 +132,27 @@ */ /*! - \fn QPair &QPair::operator=(const QPair<TT1, TT2> &p) + \fn QPair::QPair(QPair<TT1, TT2> &&p) \since 5.2 - Copies the pair \a p onto this pair. - - \sa qMakePair() + Move-constructs a QPair instance, making it point to the same object that + \a p was pointing to. */ /*! - \fn void QPair::swap(QPair &other) - \since 5.5 - - Swaps this pair with \a other. + \fn QPair & QPair::operator=(const QPair<TT1, TT2> &p) + \since 5.2 - Equivalent to - \code - qSwap(this->first, other.first); - qSwap(this->second, other.second); - \endcode + Copies pair \a p into this pair. - Swap overloads are found in namespace \c std as well as via - argument-dependent lookup (ADL) in \c{T}'s namespace. + \sa qMakePair() */ /*! - \fn void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) - \overload - \relates QPair - \since 5.5 + \fn QPair & QPair::operator=(QPair<TT1, TT2> &&p) + \since 5.2 - Swaps \a lhs with \a rhs. + Move-assigns pair \a p into this pair instance. */ /*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) diff --git a/src/corelib/tools/qregularexpression.cpp b/src/corelib/tools/qregularexpression.cpp index 18dd2d12c2..47cad6349c 100644 --- a/src/corelib/tools/qregularexpression.cpp +++ b/src/corelib/tools/qregularexpression.cpp @@ -1830,6 +1830,13 @@ bool QRegularExpression::operator==(const QRegularExpression &re) const } /*! + \fn QRegularExpression & QRegularExpression::operator=(QRegularExpression && re) + + Move-assigns the regular expression \a re to this object, and returns a reference + to the copy. Both the pattern and the pattern options are copied. +*/ + +/*! \fn bool QRegularExpression::operator!=(const QRegularExpression &re) const Returns \c true if the regular expression is different from \a re, or @@ -1956,6 +1963,13 @@ QRegularExpressionMatch &QRegularExpressionMatch::operator=(const QRegularExpres } /*! + \fn QRegularExpressionMatch &QRegularExpressionMatch::operator=(QRegularExpressionMatch &&match) + + Move-assigns the match result \a match to this object, and returns a reference + to the copy. +*/ + +/*! \fn void QRegularExpressionMatch::swap(QRegularExpressionMatch &other) Swaps the match result \a other with this match result. This @@ -2320,6 +2334,12 @@ QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(cons } /*! + \fn QRegularExpressionMatchIterator &QRegularExpressionMatchIterator::operator=(QRegularExpressionMatchIterator &&iterator) + + Move-assigns the \a iterator to this object. +*/ + +/*! \fn void QRegularExpressionMatchIterator::swap(QRegularExpressionMatchIterator &other) Swaps the iterator \a other with this iterator object. This operation is diff --git a/src/corelib/tools/qringbuffer.cpp b/src/corelib/tools/qringbuffer.cpp new file mode 100644 index 0000000000..bcf6d2646e --- /dev/null +++ b/src/corelib/tools/qringbuffer.cpp @@ -0,0 +1,309 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Copyright (C) 2015 Alex Trotsenko <alex1973tr@gmail.com> +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "private/qringbuffer_p.h" +#include <string.h> + +QT_BEGIN_NAMESPACE + +/*! + \internal + + Access the bytes at a specified position the out-variable length will + contain the amount of bytes readable from there, e.g. the amount still + the same QByteArray +*/ +const char *QRingBuffer::readPointerAtPosition(qint64 pos, qint64 &length) const +{ + if (pos >= 0) { + pos += head; + for (int i = 0; i < buffers.size(); ++i) { + length = (i == tailBuffer ? tail : buffers[i].size()); + if (length > pos) { + length -= pos; + return buffers[i].constData() + pos; + } + pos -= length; + } + } + + length = 0; + return 0; +} + +void QRingBuffer::free(qint64 bytes) +{ + while (bytes > 0) { + const qint64 blockSize = buffers.first().size() - head; + + if (tailBuffer == 0 || blockSize > bytes) { + // keep a single block around if it does not exceed + // the basic block size, to avoid repeated allocations + // between uses of the buffer + if (bufferSize <= bytes) { + if (buffers.first().size() <= basicBlockSize) { + bufferSize = 0; + head = tail = 0; + } else { + clear(); // try to minify/squeeze us + } + } else { + Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); + head += int(bytes); + bufferSize -= bytes; + } + return; + } + + bufferSize -= blockSize; + bytes -= blockSize; + buffers.removeFirst(); + --tailBuffer; + head = 0; + } +} + +char *QRingBuffer::reserve(qint64 bytes) +{ + if (bytes <= 0 || quint64(bytes) >= QByteArray::MaxSize) + return 0; + + const qint64 newSize = bytes + tail; + // if need buffer reallocation + if (newSize > buffers.last().size()) { + if (newSize > buffers.last().capacity() && (tail >= basicBlockSize + || quint64(newSize) >= QByteArray::MaxSize)) { + // 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))); + } + + char *writePtr = buffers.last().data() + tail; + bufferSize += bytes; + Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); + tail += int(bytes); + return writePtr; +} + +/*! + \internal + + Allocate data at buffer head +*/ +char *QRingBuffer::reserveFront(qint64 bytes) +{ + if (bytes <= 0 || quint64(bytes) >= QByteArray::MaxSize) + return 0; + + if (head < bytes) { + buffers.first().remove(0, head); + if (tailBuffer == 0) + tail -= head; + + buffers.prepend(QByteArray()); + head = qMax(basicBlockSize, int(bytes)); + buffers.first().resize(head); + ++tailBuffer; + } + + head -= int(bytes); + bufferSize += bytes; + return buffers.first().data() + head; +} + +void QRingBuffer::chop(qint64 bytes) +{ + while (bytes > 0) { + if (tailBuffer == 0 || tail > bytes) { + // keep a single block around if it does not exceed + // the basic block size, to avoid repeated allocations + // between uses of the buffer + if (bufferSize <= bytes) { + if (buffers.first().size() <= basicBlockSize) { + bufferSize = 0; + head = tail = 0; + } else { + clear(); // try to minify/squeeze us + } + } else { + Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); + tail -= int(bytes); + bufferSize -= bytes; + } + return; + } + + bufferSize -= tail; + bytes -= tail; + buffers.removeLast(); + --tailBuffer; + tail = buffers.last().size(); + } +} + +void QRingBuffer::clear() +{ + buffers.erase(buffers.begin() + 1, buffers.end()); + buffers.first().clear(); + + head = tail = 0; + tailBuffer = 0; + bufferSize = 0; +} + +qint64 QRingBuffer::indexOf(char c, qint64 maxLength) 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; + } + j = 0; + } + return -1; +} + +qint64 QRingBuffer::read(char *data, qint64 maxLength) +{ + const qint64 bytesToRead = qMin(size(), maxLength); + qint64 readSoFar = 0; + while (readSoFar < bytesToRead) { + const qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, + nextDataBlockSize()); + if (data) + memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock); + readSoFar += bytesToReadFromThisBlock; + free(bytesToReadFromThisBlock); + } + return readSoFar; +} + +/*! + \internal + + Read an unspecified amount (will read the first buffer) +*/ +QByteArray QRingBuffer::read() +{ + if (bufferSize == 0) + return QByteArray(); + + QByteArray qba(buffers.takeFirst()); + + qba.reserve(0); // avoid that resizing needlessly reallocates + if (tailBuffer == 0) { + qba.resize(tail); + tail = 0; + buffers.append(QByteArray()); + } else { + --tailBuffer; + } + qba.remove(0, head); // does nothing if head is 0 + head = 0; + bufferSize -= qba.size(); + return qba; +} + +/*! + \internal + + Peek the bytes from a specified position +*/ +qint64 QRingBuffer::peek(char *data, qint64 maxLength, qint64 pos) const +{ + qint64 readSoFar = 0; + + if (pos >= 0) { + pos += head; + for (int i = 0; readSoFar < maxLength && i < buffers.size(); ++i) { + qint64 blockLength = (i == tailBuffer ? tail : buffers[i].size()); + + if (pos < blockLength) { + blockLength = qMin(blockLength - pos, maxLength - readSoFar); + memcpy(data + readSoFar, buffers[i].constData() + pos, blockLength); + readSoFar += blockLength; + pos = 0; + } else { + pos -= blockLength; + } + } + } + + return readSoFar; +} + +/*! + \internal + + Append a new buffer to the end +*/ +void QRingBuffer::append(const QByteArray &qba) +{ + if (tail == 0) { + buffers.last() = qba; + } else { + buffers.last().resize(tail); + buffers.append(qba); + ++tailBuffer; + } + tail = qba.size(); + bufferSize += tail; +} + +qint64 QRingBuffer::readLine(char *data, qint64 maxLength) +{ + if (!data || --maxLength <= 0) + return -1; + + qint64 i = indexOf('\n', maxLength); + i = read(data, i >= 0 ? (i + 1) : maxLength); + + // Terminate it. + data[i] = '\0'; + return i; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qringbuffer_p.h b/src/corelib/tools/qringbuffer_p.h index 9ca14d2987..68509a6a80 100644 --- a/src/corelib/tools/qringbuffer_p.h +++ b/src/corelib/tools/qringbuffer_p.h @@ -66,117 +66,17 @@ public: return bufferSize == 0 ? Q_NULLPTR : (buffers.first().constData() + head); } - // access the bytes at a specified position - // the out-variable length will contain the amount of bytes readable - // from there, e.g. the amount still the same QByteArray - inline const char *readPointerAtPosition(qint64 pos, qint64 &length) const { - if (pos >= 0) { - pos += head; - for (int i = 0; i < buffers.size(); ++i) { - length = (i == tailBuffer ? tail : buffers[i].size()); - if (length > pos) { - length -= pos; - return buffers[i].constData() + pos; - } - pos -= length; - } - } - - length = 0; - return 0; - } - - inline void free(qint64 bytes) { - while (bytes > 0) { - const qint64 blockSize = buffers.first().size() - head; - - if (tailBuffer == 0 || blockSize > bytes) { - // keep a single block around if it does not exceed - // the basic block size, to avoid repeated allocations - // between uses of the buffer - if (bufferSize <= bytes) { - if (buffers.first().size() <= basicBlockSize) { - bufferSize = 0; - head = tail = 0; - } else { - clear(); // try to minify/squeeze us - } - } else { - Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); - head += int(bytes); - bufferSize -= bytes; - } - return; - } - - bufferSize -= blockSize; - bytes -= blockSize; - buffers.removeFirst(); - --tailBuffer; - head = 0; - } - } - - inline char *reserve(qint64 bytes) { - if (bytes <= 0 || quint64(bytes) >= QByteArray::MaxSize) - return 0; - - const qint64 newSize = bytes + tail; - // if need buffer reallocation - if (newSize > buffers.last().size()) { - if (newSize > buffers.last().capacity() && (tail >= basicBlockSize - || quint64(newSize) >= QByteArray::MaxSize)) { - // 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))); - } - - char *writePtr = buffers.last().data() + tail; - bufferSize += bytes; - Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); - tail += int(bytes); - return writePtr; - } + Q_CORE_EXPORT const char *readPointerAtPosition(qint64 pos, qint64 &length) const; + Q_CORE_EXPORT void free(qint64 bytes); + Q_CORE_EXPORT char *reserve(qint64 bytes); + Q_CORE_EXPORT char *reserveFront(qint64 bytes); inline void truncate(qint64 pos) { if (pos < size()) chop(size() - pos); } - inline void chop(qint64 bytes) { - while (bytes > 0) { - if (tailBuffer == 0 || tail > bytes) { - // keep a single block around if it does not exceed - // the basic block size, to avoid repeated allocations - // between uses of the buffer - if (bufferSize <= bytes) { - if (buffers.first().size() <= basicBlockSize) { - bufferSize = 0; - head = tail = 0; - } else { - clear(); // try to minify/squeeze us - } - } else { - Q_ASSERT(quint64(bytes) < QByteArray::MaxSize); - tail -= int(bytes); - bufferSize -= bytes; - } - return; - } - - bufferSize -= tail; - bytes -= tail; - buffers.removeLast(); - --tailBuffer; - tail = buffers.last().size(); - } - } + Q_CORE_EXPORT void chop(qint64 bytes); inline bool isEmpty() const { return bufferSize == 0; @@ -195,156 +95,36 @@ public: *ptr = c; } - inline void ungetChar(char c) { - --head; - if (head < 0) { - if (bufferSize != 0) { - buffers.prepend(QByteArray()); - ++tailBuffer; - } else { - tail = basicBlockSize; - } - buffers.first().resize(basicBlockSize); - head = basicBlockSize - 1; - } - buffers.first()[head] = c; - ++bufferSize; - } - - inline qint64 size() const { - return bufferSize; - } - - inline void clear() { - buffers.erase(buffers.begin() + 1, buffers.end()); - buffers.first().clear(); - - head = tail = 0; - tailBuffer = 0; - bufferSize = 0; - } - - inline qint64 indexOf(char c) const { - qint64 index = 0; - qint64 j = head; - for (int i = 0; i < buffers.size(); ++i) { - const char *ptr = buffers[i].constData() + j; - j = index + (i == tailBuffer ? tail : buffers[i].size()) - j; - - while (index < j) { - if (*ptr++ == c) - return index; - ++index; - } - j = 0; - } - return -1; - } - - inline qint64 indexOf(char c, qint64 maxLength) 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; - } - j = 0; - } - return -1; - } - - inline qint64 read(char *data, qint64 maxLength) { - const qint64 bytesToRead = qMin(size(), maxLength); - qint64 readSoFar = 0; - while (readSoFar < bytesToRead) { - const qint64 bytesToReadFromThisBlock = qMin(bytesToRead - readSoFar, - nextDataBlockSize()); - if (data) - memcpy(data + readSoFar, readPointer(), bytesToReadFromThisBlock); - readSoFar += bytesToReadFromThisBlock; - free(bytesToReadFromThisBlock); - } - return readSoFar; - } - - // read an unspecified amount (will read the first buffer) - inline QByteArray read() { - if (bufferSize == 0) - return QByteArray(); - - QByteArray qba(buffers.takeFirst()); - - qba.reserve(0); // avoid that resizing needlessly reallocates - if (tailBuffer == 0) { - qba.resize(tail); - tail = 0; - buffers.append(QByteArray()); + void ungetChar(char c) + { + if (head > 0) { + --head; + buffers.first()[head] = c; + ++bufferSize; } else { - --tailBuffer; + char *ptr = reserveFront(1); + *ptr = c; } - qba.remove(0, head); // does nothing if head is 0 - head = 0; - bufferSize -= qba.size(); - return qba; } - // peek the bytes from a specified position - inline qint64 peek(char *data, qint64 maxLength, qint64 pos = 0) const - { - qint64 readSoFar = 0; - - if (pos >= 0) { - pos += head; - for (int i = 0; readSoFar < maxLength && i < buffers.size(); ++i) { - qint64 blockLength = (i == tailBuffer ? tail : buffers[i].size()); - - if (pos < blockLength) { - blockLength = qMin(blockLength - pos, maxLength - readSoFar); - memcpy(data + readSoFar, buffers[i].constData() + pos, blockLength); - readSoFar += blockLength; - pos = 0; - } else { - pos -= blockLength; - } - } - } - return readSoFar; + inline qint64 size() const { + return bufferSize; } - // append a new buffer to the end - inline void append(const QByteArray &qba) { - if (tail == 0) { - buffers.last() = qba; - } else { - buffers.last().resize(tail); - buffers.append(qba); - ++tailBuffer; - } - tail = qba.size(); - bufferSize += tail; - } + 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 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); } - inline qint64 readLine(char *data, qint64 maxLength) { - if (!data || --maxLength <= 0) - return -1; - - qint64 i = indexOf('\n', maxLength); - i = read(data, i >= 0 ? (i + 1) : maxLength); - - // Terminate it. - data[i] = '\0'; - return i; - } + Q_CORE_EXPORT qint64 readLine(char *data, qint64 maxLength); inline bool canReadLine() const { return indexOf('\n') >= 0; diff --git a/src/corelib/tools/qscopedpointer.cpp b/src/corelib/tools/qscopedpointer.cpp index 35551f4061..c113c38aa2 100644 --- a/src/corelib/tools/qscopedpointer.cpp +++ b/src/corelib/tools/qscopedpointer.cpp @@ -255,6 +255,13 @@ QT_BEGIN_NAMESPACE */ /*! + \fn QScopedArrayPointer::QScopedArrayPointer(D * p, QtPrivate::QScopedArrayEnsureSameType<T, D>::Type = 0) + \internal + + Constructs a QScopedArrayPointer and stores the array of objects. +*/ + +/*! \fn T *QScopedArrayPointer::operator[](int i) Provides access to entry \a i of the scoped pointer's array of diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index e4688711d6..5a9c75fe07 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -137,6 +137,7 @@ public: typedef QHash<T, QHashDummyValue> Hash; typename Hash::const_iterator i; friend class iterator; + friend class QSet<T>; public: typedef std::bidirectional_iterator_tag iterator_category; @@ -191,6 +192,7 @@ public: inline const_iterator constFind(const T &value) const { return find(value); } QSet<T> &unite(const QSet<T> &other); QSet<T> &intersect(const QSet<T> &other); + bool intersects(const QSet<T> &other) const; QSet<T> &subtract(const QSet<T> &other); // STL compatibility @@ -284,6 +286,34 @@ Q_INLINE_TEMPLATE QSet<T> &QSet<T>::intersect(const QSet<T> &other) } template <class T> +Q_INLINE_TEMPLATE bool QSet<T>::intersects(const QSet<T> &other) const +{ + const bool otherIsBigger = other.size() > size(); + const QSet &smallestSet = otherIsBigger ? *this : other; + const QSet &biggestSet = otherIsBigger ? other : *this; + const bool equalSeeds = q_hash.d->seed == other.q_hash.d->seed; + typename QSet::const_iterator i = smallestSet.cbegin(); + typename QSet::const_iterator e = smallestSet.cend(); + + if (Q_LIKELY(equalSeeds)) { + // If seeds are equal we take the fast path so no hash is recalculated. + while (i != e) { + if (*biggestSet.q_hash.findNode(*i, i.i.i->h) != biggestSet.q_hash.e) + return true; + ++i; + } + } else { + while (i != e) { + if (biggestSet.contains(*i)) + return true; + ++i; + } + } + + return false; +} + +template <class T> Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other) { QSet<T> copy1(*this); diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc index 94cfa729f5..495329b90d 100644 --- a/src/corelib/tools/qset.qdoc +++ b/src/corelib/tools/qset.qdoc @@ -127,6 +127,13 @@ */ /*! + \fn QSet::QSet(QSet && other) + + Move-constructs a QSet instance, making it point to the same object that \a other was pointing to. +*/ + + +/*! \fn QSet<T> &QSet::operator=(const QSet<T> &other) Assigns the \a other set to this set and returns a reference to @@ -134,6 +141,12 @@ */ /*! + \fn QSet<T> &QSet::operator=(QSet<T> &&other) + + Move-assigns the \a other set to this set. +*/ + +/*! \fn void QSet::swap(QSet<T> &other) Swaps set \a other with this set. This operation is very fast and @@ -490,7 +503,17 @@ Removes all items from this set that are not contained in the \a other set. A reference to this set is returned. - \sa operator&=(), unite(), subtract() + \sa intersects(), operator&=(), unite(), subtract() +*/ + +/*! + \fn bool QSet::intersects(const QSet<T> &other) const + \since 5.6 + + Returns \c true if this set has at least one item in common with + \a other. + + \sa contains(), intersect() */ /*! diff --git a/src/corelib/tools/qsimd.cpp b/src/corelib/tools/qsimd.cpp index 52ffc161bf..d572dd209c 100644 --- a/src/corelib/tools/qsimd.cpp +++ b/src/corelib/tools/qsimd.cpp @@ -39,7 +39,9 @@ #if defined(Q_OS_WIN) # if defined(Q_OS_WINCE) # include <qt_windows.h> -# include <cmnintrin.h> +# if _WIN32_WCE < 0x800 +# include <cmnintrin.h> +# endif # endif # if !defined(Q_CC_GNU) # ifndef Q_OS_WINCE diff --git a/src/corelib/tools/qsize.h b/src/corelib/tools/qsize.h index 6e7ed40dff..e71eeb607e 100644 --- a/src/corelib/tools/qsize.h +++ b/src/corelib/tools/qsize.h @@ -54,15 +54,15 @@ public: Q_DECL_RELAXED_CONSTEXPR inline void setWidth(int w) Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline void setHeight(int h) Q_DECL_NOTHROW; void transpose() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QSize transposed() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QSize transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; inline void scale(int w, int h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; inline void scale(const QSize &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - QSize scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; + QSize scaled(int w, int h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + QSize scaled(const QSize &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; - Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QSize expandedTo(const QSize &) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + Q_DECL_CONSTEXPR inline QSize boundedTo(const QSize &) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; Q_DECL_RELAXED_CONSTEXPR inline int &rwidth() Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline int &rheight() Q_DECL_NOTHROW; @@ -214,15 +214,15 @@ public: Q_DECL_RELAXED_CONSTEXPR inline void setWidth(qreal w) Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline void setHeight(qreal h) Q_DECL_NOTHROW; void transpose() Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QSizeF transposed() const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QSizeF transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT; inline void scale(qreal w, qreal h, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; inline void scale(const QSizeF &s, Qt::AspectRatioMode mode) Q_DECL_NOTHROW; - QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; - QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW; + QSizeF scaled(qreal w, qreal h, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + QSizeF scaled(const QSizeF &s, Qt::AspectRatioMode mode) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; - Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const Q_DECL_NOTHROW; - Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const Q_DECL_NOTHROW; + Q_DECL_CONSTEXPR inline QSizeF expandedTo(const QSizeF &) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + Q_DECL_CONSTEXPR inline QSizeF boundedTo(const QSizeF &) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; Q_DECL_RELAXED_CONSTEXPR inline qreal &rwidth() Q_DECL_NOTHROW; Q_DECL_RELAXED_CONSTEXPR inline qreal &rheight() Q_DECL_NOTHROW; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index 373d25c6ad..2585686156 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -2721,6 +2721,8 @@ bool QString::operator<(QLatin1String other) const /*! \fn bool QString::operator<=(const QString &s1, const QString &s2) + \relates Qstring + Returns \c true if string \a s1 is lexically less than or equal to string \a s2; otherwise returns \c false. @@ -2766,9 +2768,10 @@ bool QString::operator<(QLatin1String other) const */ /*! \fn bool QString::operator>(const QString &s1, const QString &s2) + \relates QString - Returns \c true if string \a s1 is lexically greater than string \a - s2; otherwise returns \c false. + Returns \c true if string \a s1 is lexically greater than string \a s2; + otherwise returns \c false. The comparison is based exclusively on the numeric Unicode values of the characters and is very fast, but is not what a human would @@ -8923,6 +8926,110 @@ bool operator<(const QStringRef &s1,const QStringRef &s2) */ /*! + \fn bool QStringRef::operator==(const char * s) const + + \overload operator==() + + The \a s byte array is converted to a QStringRef using the + fromUtf8() function. This function stops conversion at the + first NUL character found, or the end of the byte array. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is lexically equal to the parameter + string \a s. Otherwise returns \c false. + +*/ + +/*! + \fn bool QStringRef::operator!=(const char * s) const + + \overload operator!=() + + The \a s const char pointer is converted to a QStringRef using + the fromUtf8() function. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is not lexically equal to the parameter + string \a s. Otherwise returns \c false. +*/ + +/*! + \fn bool QStringRef::operator<(const char * s) const + + \overload operator<() + + The \a s const char pointer is converted to a QStringRef using + the fromUtf8() function. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is lexically smaller than the parameter + string \a s. Otherwise returns \c false. +*/ + +/*! + \fn bool QStringRef::operator<=(const char * s) const + + \overload operator<=() + + The \a s const char pointer is converted to a QStringRef using + the fromUtf8() function. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is lexically smaller than or equal to the parameter + string \a s. Otherwise returns \c false. +*/ + +/*! + \fn bool QStringRef::operator>(const char * s) const + + + \overload operator>() + + The \a s const char pointer is converted to a QStringRef using + the fromUtf8() function. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is lexically greater than the parameter + string \a s. Otherwise returns \c false. +*/ + +/*! + \fn bool QStringRef::operator>= (const char * s) const + + \overload operator>=() + + The \a s const char pointer is converted to a QStringRef using + the fromUtf8() function. + + You can disable this operator by defining \c + QT_NO_CAST_FROM_ASCII when you compile your applications. This + can be useful if you want to ensure that all user-visible strings + go through QObject::tr(), for example. + + Returns \c true if this string is lexically greater than or equal to the + parameter string \a s. Otherwise returns \c false. +*/ +/*! \typedef QString::Data \internal */ @@ -10332,7 +10439,6 @@ QString QString::toHtmlEscaped() const \endlist */ - /*! \internal */ diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index 532b294c28..670d94279d 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -498,7 +498,7 @@ public: }; QString normalized(NormalizationForm mode, QChar::UnicodeVersion version = QChar::Unicode_Unassigned) const Q_REQUIRED_RESULT; - QString repeated(int times) const; + QString repeated(int times) const Q_REQUIRED_RESULT; const ushort *utf16() const; diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 4f46764697..b57954dc03 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -951,7 +951,7 @@ Returns a reference to the first item in the vector. This function assumes that the vector isn't empty. - \sa last(), isEmpty() + \sa last(), isEmpty(), constFirst() */ /*! \fn const T& QVector::first() const @@ -959,12 +959,21 @@ \overload */ +/*! \fn const T& QVector::constFirst() const + \since 5.6 + + Returns a const reference to the first item in the vector. This + function assumes that the vector isn't empty. + + \sa constLast(), isEmpty(), first() +*/ + /*! \fn T& QVector::last() Returns a reference to the last item in the vector. This function assumes that the vector isn't empty. - \sa first(), isEmpty() + \sa first(), isEmpty(), constLast() */ /*! \fn const T& QVector::last() const @@ -972,6 +981,15 @@ \overload */ +/*! \fn const T& QVector::constLast() const + \since 5.6 + + Returns a const reference to the last item in the vector. This function + assumes that the vector isn't empty. + + \sa constFirst(), isEmpty(), last() +*/ + /*! \fn T QVector::value(int i) const Returns the value at index position \a i in the vector. diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 2eb2dc4550..2adf2d4522 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -212,8 +212,10 @@ public: inline int count() const { return d->size; } inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); } inline const T &first() const { Q_ASSERT(!isEmpty()); return *begin(); } + inline const T &constFirst() const { Q_ASSERT(!isEmpty()); return *begin(); } inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); } inline const T &last() const { Q_ASSERT(!isEmpty()); return *(end()-1); } + inline const T &constLast() const { Q_ASSERT(!isEmpty()); return *(end()-1); } inline bool startsWith(const T &t) const { return !isEmpty() && first() == t; } inline bool endsWith(const T &t) const { return !isEmpty() && last() == t; } QVector<T> mid(int pos, int len = -1) const; diff --git a/src/corelib/tools/tools.pri b/src/corelib/tools/tools.pri index 5e4a22e283..1dba6784b6 100644 --- a/src/corelib/tools/tools.pri +++ b/src/corelib/tools/tools.pri @@ -106,6 +106,7 @@ SOURCES += \ tools/qrect.cpp \ tools/qregexp.cpp \ tools/qrefcount.cpp \ + tools/qringbuffer.cpp \ tools/qshareddata.cpp \ tools/qsharedpointer.cpp \ tools/qsimd.cpp \ |