diff options
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 8 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.cpp | 142 | ||||
-rw-r--r-- | src/corelib/tools/qbytearray.h | 46 | ||||
-rw-r--r-- | src/corelib/tools/qstring.cpp | 35 | ||||
-rw-r--r-- | src/corelib/tools/qstring.h | 8 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.cpp | 9 | ||||
-rw-r--r-- | src/gui/kernel/qguiapplication.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.cpp | 12 | ||||
-rw-r--r-- | src/gui/kernel/qscreen.h | 12 | ||||
-rw-r--r-- | src/gui/kernel/qwindow.h | 5 | ||||
-rw-r--r-- | tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro | 1 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 6 | ||||
-rw-r--r-- | tests/auto/other/modeltest/dynamictreemodel.cpp | 12 | ||||
-rw-r--r-- | tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp | 1 |
14 files changed, 148 insertions, 151 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 654170fabb..82e0435d0a 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -834,7 +834,13 @@ static bool customConvert(const QVariant::Private *, int, void *, bool *ok) } #if !defined(QT_NO_DEBUG_STREAM) -static void customStreamDebug(QDebug, const QVariant &) {} +static void customStreamDebug(QDebug dbg, const QVariant &variant) { +#ifndef QT_BOOTSTRAPPED + QMetaType::TypeFlags flags = QMetaType::typeFlags(variant.userType()); + if (flags & QMetaType::PointerToQObject) + dbg.nospace() << variant.value<QObject*>(); +#endif +} #endif const QVariant::Handler qt_custom_variant_handler = { diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index 43f666e075..31cf65b78d 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -579,13 +579,13 @@ QByteArray qUncompress(const uchar* data, int nbytes) } d->ref.initializeOwned(); d->size = len; - d->alloc = len; + d->alloc = uint(len) + 1u; d->capacityReserved = false; d->offset = sizeof(QByteArrayData); d->data()[len] = 0; { - QByteArrayDataPtr dataPtr = { d.take() }; + QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(d.take()) }; return QByteArray(dataPtr); } @@ -618,9 +618,6 @@ static inline char qToLower(char c) return c; } -const QStaticByteArrayData<1> QByteArray::shared_null = { Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(0), { 0 } }; -const QStaticByteArrayData<1> QByteArray::shared_empty = { Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER(0), { 0 } }; - /*! \class QByteArray \brief The QByteArray class provides an array of bytes. @@ -897,7 +894,7 @@ QByteArray &QByteArray::operator=(const QByteArray & other) { other.d->ref.ref(); if (!d->ref.deref()) - free(d); + Data::deallocate(d); d = other.d; return *this; } @@ -913,20 +910,21 @@ QByteArray &QByteArray::operator=(const char *str) { Data *x; if (!str) { - x = shared_null.data_ptr(); + x = Data::sharedNull(); } else if (!*str) { - x = shared_empty.data_ptr(); + x = Data::allocate(0); } else { int len = strlen(str); - if (d->ref.isShared() || len > int(d->alloc) || (len < d->size && len < int(d->alloc) >> 1)) - reallocData(uint(len) + 1u); + if (d->ref.isShared() || uint(len) + 1u > d->alloc + || (len < d->size && uint(len) + 1u < uint(d->alloc >> 1))) + reallocData(uint(len) + 1u, d->detachFlags()); x = d; - memcpy(x->data(), str, len + 1); // include null terminator + memcpy(x->data(), str, uint(len) + 1u); // include null terminator x->size = len; } x->ref.ref(); if (!d->ref.deref()) - free(d); + Data::deallocate(d); d = x; return *this; } @@ -1321,20 +1319,16 @@ void QByteArray::chop(int n) QByteArray::QByteArray(const char *data, int size) { if (!data) { - d = shared_null.data_ptr(); + d = Data::sharedNull(); } else { if (size < 0) size = strlen(data); if (!size) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); + d = Data::allocate(uint(size) + 1u); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = size; - d->capacityReserved = false; - d->offset = sizeof(QByteArrayData); memcpy(d->data(), data, size); d->data()[size] = '\0'; } @@ -1351,15 +1345,11 @@ QByteArray::QByteArray(const char *data, int size) QByteArray::QByteArray(int size, char ch) { if (size <= 0) { - d = shared_empty.data_ptr(); + d = Data::allocate(0); } else { - d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); + d = Data::allocate(uint(size) + 1u); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = size; - d->capacityReserved = false; - d->offset = sizeof(QByteArrayData); memset(d->data(), ch, size); d->data()[size] = '\0'; } @@ -1373,13 +1363,9 @@ QByteArray::QByteArray(int size, char ch) QByteArray::QByteArray(int size, Qt::Initialization) { - d = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); + d = Data::allocate(uint(size) + 1u); Q_CHECK_PTR(d); - d->ref.initializeOwned(); d->size = size; - d->alloc = size; - d->capacityReserved = false; - d->offset = sizeof(QByteArrayData); d->data()[size] = '\0'; } @@ -1395,7 +1381,6 @@ QByteArray::QByteArray(int size, Qt::Initialization) \sa size(), truncate() */ - void QByteArray::resize(int size) { if (size < 0) @@ -1407,11 +1392,11 @@ void QByteArray::resize(int size) } if (size == 0 && !d->capacityReserved) { - Data *x = shared_empty.data_ptr(); + Data *x = Data::allocate(0); if (!d->ref.deref()) - free(d); + Data::deallocate(d); d = x; - } else if (d == &shared_null.ba || d == &shared_empty.ba) { + } else if (d->size == 0 && d->ref.isStatic()) { // // Optimize the idiom: // QByteArray a; @@ -1420,19 +1405,16 @@ void QByteArray::resize(int size) // which is used in place of the Qt 3 idiom: // QByteArray a(sz); // - Data *x = static_cast<Data *>(malloc(sizeof(Data) + size + 1)); + Data *x = Data::allocate(uint(size) + 1u); Q_CHECK_PTR(x); - x->ref.initializeOwned(); x->size = size; - x->alloc = size; - x->capacityReserved = false; - x->offset = sizeof(QByteArrayData); x->data()[size] = '\0'; d = x; } else { - if (d->ref.isShared() || size > int(d->alloc) - || (!d->capacityReserved && size < d->size && size < int(d->alloc) >> 1)) - reallocData(uint(size) + 1u, true); + if (d->ref.isShared() || uint(size) + 1u > d->alloc + || (!d->capacityReserved && size < d->size + && uint(size) + 1u < uint(d->alloc >> 1))) + reallocData(uint(size) + 1u, d->detachFlags() | Data::Grow); if (d->alloc) { d->size = size; d->data()[size] = '\0'; @@ -1459,29 +1441,24 @@ QByteArray &QByteArray::fill(char ch, int size) return *this; } -void QByteArray::reallocData(uint alloc, bool grow) +void QByteArray::reallocData(uint alloc, Data::AllocationOptions options) { - if (grow) - alloc = qAllocMore(alloc, sizeof(Data)); - if (d->ref.isShared() || IS_RAW_DATA(d)) { - Data *x = static_cast<Data *>(malloc(sizeof(Data) + alloc)); + Data *x = Data::allocate(alloc, options); Q_CHECK_PTR(x); - x->ref.initializeOwned(); x->size = qMin(int(alloc) - 1, d->size); - x->alloc = alloc - 1u; - x->capacityReserved = d->capacityReserved; - x->offset = sizeof(QByteArrayData); ::memcpy(x->data(), d->data(), x->size); x->data()[x->size] = '\0'; if (!d->ref.deref()) - free(d); + Data::deallocate(d); d = x; } else { + if (options & Data::Grow) + alloc = qAllocMore(alloc, sizeof(Data)); Data *x = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc)); Q_CHECK_PTR(x); - x->alloc = alloc - 1u; - x->offset = sizeof(QByteArrayData); + x->alloc = alloc; + x->capacityReserved = (options & Data::CapacityReserved) ? 1 : 0; d = x; } } @@ -1534,9 +1511,9 @@ QByteArray QByteArray::nulTerminated() const QByteArray &QByteArray::prepend(const QByteArray &ba) { - if ((d == &shared_null.ba || d == &shared_empty.ba) && !IS_RAW_DATA(ba.d)) { + if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) { *this = ba; - } else if (ba.d != &shared_null.ba) { + } else if (ba.d->size != 0) { QByteArray tmp = *this; *this = ba; append(tmp); @@ -1565,8 +1542,8 @@ QByteArray &QByteArray::prepend(const char *str) QByteArray &QByteArray::prepend(const char *str, int len) { if (str) { - if (d->ref.isShared() || d->size + len > int(d->alloc)) - reallocData(uint(d->size + len) + 1u, true); + if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); memmove(d->data()+len, d->data(), d->size); memcpy(d->data(), str, len); d->size += len; @@ -1583,8 +1560,8 @@ QByteArray &QByteArray::prepend(const char *str, int len) QByteArray &QByteArray::prepend(char ch) { - if (d->ref.isShared() || d->size + 1 > int(d->alloc)) - reallocData(uint(d->size) + 2u, true); + if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) + reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); memmove(d->data()+1, d->data(), d->size); d->data()[0] = ch; ++d->size; @@ -1618,11 +1595,11 @@ QByteArray &QByteArray::prepend(char ch) QByteArray &QByteArray::append(const QByteArray &ba) { - if ((d == &shared_null.ba || d == &shared_empty.ba) && !IS_RAW_DATA(ba.d)) { + if (d->size == 0 && d->ref.isStatic() && !IS_RAW_DATA(ba.d)) { *this = ba; - } else if (ba.d != &shared_null.ba) { - if (d->ref.isShared() || d->size + ba.d->size > int(d->alloc)) - reallocData(uint(d->size + ba.d->size) + 1u, true); + } else if (ba.d->size != 0) { + if (d->ref.isShared() || uint(d->size + ba.d->size) + 1u > d->alloc) + reallocData(uint(d->size + ba.d->size) + 1u, d->detachFlags() | Data::Grow); memcpy(d->data() + d->size, ba.d->data(), ba.d->size); d->size += ba.d->size; d->data()[d->size] = '\0'; @@ -1655,8 +1632,8 @@ QByteArray& QByteArray::append(const char *str) { if (str) { int len = strlen(str); - if (d->ref.isShared() || d->size + len > int(d->alloc)) - reallocData(uint(d->size + len) + 1u, true); + if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); memcpy(d->data() + d->size, str, len + 1); // include null terminator d->size += len; } @@ -1680,8 +1657,8 @@ QByteArray &QByteArray::append(const char *str, int len) if (len < 0) len = qstrlen(str); if (str && len) { - if (d->ref.isShared() || d->size + len > int(d->alloc)) - reallocData(uint(d->size + len) + 1u, true); + if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) + reallocData(uint(d->size + len) + 1u, d->detachFlags() | Data::Grow); memcpy(d->data() + d->size, str, len); // include null terminator d->size += len; d->data()[d->size] = '\0'; @@ -1697,8 +1674,8 @@ QByteArray &QByteArray::append(const char *str, int len) QByteArray& QByteArray::append(char ch) { - if (d->ref.isShared() || d->size + 1 > int(d->alloc)) - reallocData(uint(d->size) + 2u, true); + if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) + reallocData(uint(d->size) + 2u, d->detachFlags() | Data::Grow); d->data()[d->size++] = ch; d->data()[d->size] = '\0'; return *this; @@ -2206,7 +2183,7 @@ QByteArray QByteArray::repeated(int times) const QByteArray result; result.reserve(resultSize); - if (int(result.d->alloc) != resultSize) + if (result.d->alloc != uint(resultSize) + 1u) return QByteArray(); // not enough memory memcpy(result.d->data(), d->data(), d->size); @@ -2661,7 +2638,7 @@ QByteArray QByteArray::right(int len) const QByteArray QByteArray::mid(int pos, int len) const { - if (d == &shared_null.ba || d == &shared_empty.ba || pos > d->size) + if ((d->size == 0 && d->ref.isStatic()) || pos > d->size) return QByteArray(); if (len < 0) len = d->size - pos; @@ -2731,8 +2708,8 @@ QByteArray QByteArray::toUpper() const void QByteArray::clear() { if (!d->ref.deref()) - free(d); - d = shared_null.data_ptr(); + Data::deallocate(d); + d = Data::sharedNull(); } #if !defined(QT_NO_DATASTREAM) || (defined(QT_BOOTSTRAPPED) && !defined(QT_BUILD_QMAKE)) @@ -3174,7 +3151,7 @@ QByteArray QByteArray::trimmed() const } int l = end - start + 1; if (l <= 0) { - QByteArrayDataPtr empty = { shared_empty.data_ptr() }; + QByteArrayDataPtr empty = { reinterpret_cast<QByteArrayData *>(Data::allocate(0)) }; return QByteArray(empty); } return QByteArray(s+start, l); @@ -3254,7 +3231,7 @@ QByteArray QByteArray::rightJustified(int width, char fill, bool truncate) const return result; } -bool QByteArray::isNull() const { return d == &shared_null.ba; } +bool QByteArray::isNull() const { return d == QArrayData::sharedNull(); } /*! @@ -3882,19 +3859,14 @@ QByteArray QByteArray::fromRawData(const char *data, int size) { Data *x; if (!data) { - x = shared_null.data_ptr(); + x = Data::sharedNull(); } else if (!size) { - x = shared_empty.data_ptr(); + x = Data::allocate(0); } else { - x = static_cast<Data *>(malloc(sizeof(Data))); + x = Data::fromRawData(data, size); Q_CHECK_PTR(x); - x->ref.initializeOwned(); - x->size = size; - x->alloc = 0; - x->capacityReserved = false; - x->offset = data - reinterpret_cast<char *>(x); } - QByteArrayDataPtr dataPtr = { x }; + QByteArrayDataPtr dataPtr = { reinterpret_cast<QByteArrayData *>(x) }; return QByteArray(dataPtr); } diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h index 194555334f..45be63aa9b 100644 --- a/src/corelib/tools/qbytearray.h +++ b/src/corelib/tools/qbytearray.h @@ -44,6 +44,7 @@ #include <QtCore/qrefcount.h> #include <QtCore/qnamespace.h> +#include <QtCore/qarraydata.h> #include <stdlib.h> #include <string.h> @@ -121,6 +122,8 @@ template <typename T> class QList; struct QByteArrayData { + // Keep in sync with QArrayData + QtPrivate::RefCount ref; int size; uint alloc : 31; @@ -132,6 +135,12 @@ struct QByteArrayData inline const char *data() const { return reinterpret_cast<const char *>(this) + offset; } }; +Q_STATIC_ASSERT(sizeof(QArrayData) == sizeof(QByteArrayData)); +Q_STATIC_ASSERT(offsetof(QArrayData, ref) == offsetof(QByteArrayData, ref)); +Q_STATIC_ASSERT(offsetof(QArrayData, size) == offsetof(QByteArrayData, size)); +// Can't use offsetof on bitfield members alloc, capacityReserved +Q_STATIC_ASSERT(offsetof(QArrayData, offset) == offsetof(QByteArrayData, offset)); + template<int N> struct QStaticByteArrayData { QByteArrayData ba; @@ -194,11 +203,10 @@ struct QByteArrayDataPtr # define QByteArrayLiteral(str) (str) #endif - class Q_CORE_EXPORT QByteArray { private: - typedef QByteArrayData Data; + typedef QTypedArrayData<char> Data; public: inline QByteArray(); @@ -399,14 +407,15 @@ public: int length() const { return d->size; } bool isNull() const; - Q_DECL_CONSTEXPR inline QByteArray(QByteArrayDataPtr dd) : d(dd.ptr) {} + Q_DECL_CONSTEXPR inline QByteArray(QByteArrayDataPtr dd) + : d(reinterpret_cast<Data *>(dd.ptr)) + { + } private: operator QNoImplicitBoolCast() const; - static const QStaticByteArrayData<1> shared_null; - static const QStaticByteArrayData<1> shared_empty; Data *d; - void reallocData(uint alloc, bool grow = false); + void reallocData(uint alloc, Data::AllocationOptions options); void expand(int i); QByteArray nulTerminated() const; @@ -418,8 +427,8 @@ public: inline DataPtr &data_ptr() { return d; } }; -inline QByteArray::QByteArray(): d(shared_null.data_ptr()) { } -inline QByteArray::~QByteArray() { if (!d->ref.deref()) free(d); } +inline QByteArray::QByteArray(): d(Data::sharedNull()) { } +inline QByteArray::~QByteArray() { if (!d->ref.deref()) Data::deallocate(d); } inline int QByteArray::size() const { return d->size; } @@ -445,32 +454,31 @@ inline const char *QByteArray::data() const inline const char *QByteArray::constData() const { return d->data(); } inline void QByteArray::detach() -{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u); } +{ if (d->ref.isShared() || (d->offset != sizeof(QByteArrayData))) reallocData(uint(d->size) + 1u, d->detachFlags()); } inline bool QByteArray::isDetached() const { return !d->ref.isShared(); } inline QByteArray::QByteArray(const QByteArray &a) : d(a.d) { d->ref.ref(); } inline int QByteArray::capacity() const -{ return d->alloc; } +{ return d->alloc ? d->alloc - 1 : 0; } inline void QByteArray::reserve(int asize) { - if (d->ref.isShared() || asize > int(d->alloc)) - reallocData(uint(asize) + 1u); - - if (!d->capacityReserved) { - // cannot set unconditionally, since d could be the shared_null/shared_empty (which is const) + if (d->ref.isShared() || uint(asize) + 1u > d->alloc) { + reallocData(uint(asize) + 1u, d->detachFlags() | Data::CapacityReserved); + } else { + // cannot set unconditionally, since d could be the shared_null or + // otherwise static d->capacityReserved = true; } } inline void QByteArray::squeeze() { - if (d->ref.isShared() || d->size < int(d->alloc)) - reallocData(uint(d->size) + 1u); - - if (d->capacityReserved) { + if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) { + reallocData(uint(d->size) + 1u, d->detachFlags() & ~Data::CapacityReserved); + } else { // cannot set unconditionally, since d could be shared_null or // otherwise static. d->capacityReserved = false; diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index e62211ba58..a536a091a1 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -1049,11 +1049,11 @@ QString::QString(const QChar *unicode, int size) if (!size) { d = shared_empty.data_ptr(); } else { - d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); Q_CHECK_PTR(d); d->ref.initializeOwned(); d->size = size; - d->alloc = (uint) size; + d->alloc = uint(size) + 1u; d->capacityReserved = false; d->offset = sizeof(QStringData); memcpy(d->data(), unicode, size * sizeof(QChar)); @@ -1073,11 +1073,11 @@ QString::QString(int size, QChar ch) if (size <= 0) { d = shared_empty.data_ptr(); } else { - d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); Q_CHECK_PTR(d); d->ref.initializeOwned(); d->size = size; - d->alloc = (uint) size; + d->alloc = uint(size) + 1u; d->capacityReserved = false; d->offset = sizeof(QStringData); d->data()[size] = '\0'; @@ -1097,11 +1097,11 @@ QString::QString(int size, QChar ch) */ QString::QString(int size, Qt::Initialization) { - d = (Data*) ::malloc(sizeof(Data)+(size+1)*sizeof(QChar)); + d = (Data*) ::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar)); Q_CHECK_PTR(d); d->ref.initializeOwned(); d->size = size; - d->alloc = (uint) size; + d->alloc = uint(size) + 1u; d->capacityReserved = false; d->offset = sizeof(QStringData); d->data()[size] = '\0'; @@ -1123,7 +1123,7 @@ QString::QString(QChar ch) Q_CHECK_PTR(d); d->ref.initializeOwned(); d->size = 1; - d->alloc = 1; + d->alloc = 2u; d->capacityReserved = false; d->offset = sizeof(QStringData); d->data()[0] = ch.unicode(); @@ -1234,8 +1234,9 @@ void QString::resize(int size) QString::free(d); d = x; } else { - if (d->ref.isShared() || size > int(d->alloc) || - (!d->capacityReserved && size < d->size && size < int(d->alloc) >> 1)) + if (d->ref.isShared() || uint(size) + 1u > d->alloc + || (!d->capacityReserved && size < d->size + && uint(size) + 1u < uint(d->alloc >> 1))) reallocData(uint(size) + 1u, true); if (d->alloc) { d->size = size; @@ -1304,7 +1305,7 @@ void QString::reallocData(uint alloc, bool grow) Q_CHECK_PTR(x); x->ref.initializeOwned(); x->size = qMin(int(alloc) - 1, d->size); - x->alloc = alloc - 1u; + x->alloc = alloc; x->capacityReserved = d->capacityReserved; x->offset = sizeof(QStringData); ::memcpy(x->data(), d->data(), x->size * sizeof(QChar)); @@ -1316,7 +1317,7 @@ void QString::reallocData(uint alloc, bool grow) Data *p = static_cast<Data *>(::realloc(d, sizeof(Data) + alloc * sizeof(QChar))); Q_CHECK_PTR(p); d = p; - d->alloc = alloc - 1u; + d->alloc = alloc; d->offset = sizeof(QStringData); } } @@ -1524,7 +1525,7 @@ QString &QString::append(const QString &str) if (d == &shared_null.str) { operator=(str); } else { - if (d->ref.isShared() || d->size + str.d->size > int(d->alloc)) + if (d->ref.isShared() || uint(d->size + str.d->size) + 1u > d->alloc) reallocData(uint(d->size + str.d->size) + 1u, true); memcpy(d->data() + d->size, str.d->data(), str.d->size * sizeof(QChar)); d->size += str.d->size; @@ -1544,7 +1545,7 @@ QString &QString::append(const QLatin1String &str) const uchar *s = (const uchar *)str.latin1(); if (s) { int len = str.size(); - if (d->ref.isShared() || d->size + len > int(d->alloc)) + if (d->ref.isShared() || uint(d->size + len) + 1u > d->alloc) reallocData(uint(d->size + len) + 1u, true); ushort *i = d->data() + d->size; while ((*i++ = *s++)) @@ -1587,7 +1588,7 @@ QString &QString::append(const QLatin1String &str) */ QString &QString::append(QChar ch) { - if (d->ref.isShared() || d->size + 1 > int(d->alloc)) + if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) reallocData(uint(d->size) + 2u, true); d->data()[d->size++] = ch.unicode(); d->data()[d->size] = '\0'; @@ -4056,11 +4057,11 @@ QString::Data *QString::fromLatin1_helper(const char *str, int size) } else { if (size < 0) size = qstrlen(str); - d = static_cast<Data *>(::malloc(sizeof(Data) + (size+1) * sizeof(QChar))); + d = static_cast<Data *>(::malloc(sizeof(Data) + (uint(size) + 1u) * sizeof(QChar))); Q_CHECK_PTR(d); d->ref.initializeOwned(); d->size = size; - d->alloc = (uint) size; + d->alloc = uint(size) + 1u; d->capacityReserved = false; d->offset = sizeof(QStringData); d->data()[size] = '\0'; @@ -6502,7 +6503,7 @@ QString QString::repeated(int times) const QString result; result.reserve(resultSize); - if (int(result.d->alloc) != resultSize) + if (result.d->alloc != uint(resultSize) + 1u) return QString(); // not enough memory memcpy(result.d->data(), d->data(), d->size * sizeof(ushort)); diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h index a9f2484de6..edb140b682 100644 --- a/src/corelib/tools/qstring.h +++ b/src/corelib/tools/qstring.h @@ -369,7 +369,7 @@ public: inline QString &prepend(const QLatin1String &s) { return insert(0, s); } inline QString &operator+=(QChar c) { - if (d->ref.isShared() || d->size + 1 > int(d->alloc)) + if (d->ref.isShared() || uint(d->size) + 2u > d->alloc) reallocData(uint(d->size) + 2u, true); d->data()[d->size++] = c.unicode(); d->data()[d->size] = '\0'; @@ -754,7 +754,7 @@ inline void QString::clear() inline QString::QString(const QString &other) : d(other.d) { Q_ASSERT(&other != this); d->ref.ref(); } inline int QString::capacity() const -{ return d->alloc; } +{ return d->alloc ? d->alloc - 1 : 0; } inline QString &QString::setNum(short n, int base) { return setNum(qlonglong(n), base); } inline QString &QString::setNum(ushort n, int base) @@ -906,7 +906,7 @@ inline QString::~QString() { if (!d->ref.deref()) free(d); } inline void QString::reserve(int asize) { - if (d->ref.isShared() || asize > int(d->alloc)) + if (d->ref.isShared() || uint(asize) + 1u > d->alloc) reallocData(uint(asize) + 1u); if (!d->capacityReserved) { @@ -917,7 +917,7 @@ inline void QString::reserve(int asize) inline void QString::squeeze() { - if (d->ref.isShared() || d->size < int(d->alloc)) + if (d->ref.isShared() || uint(d->size) + 1u < d->alloc) reallocData(uint(d->size) + 1u); if (d->capacityReserved) { diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 36b2d261e4..9ffc35a608 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -2132,12 +2132,11 @@ void QGuiApplication::restoreOverrideCursor() \sa QStyleHints */ -QStyleHints *QGuiApplication::styleHints() const +QStyleHints *QGuiApplication::styleHints() { - Q_D(const QGuiApplication); - if (!d->styleHints) - const_cast<QGuiApplicationPrivate *>(d)->styleHints = new QStyleHints(); - return d->styleHints; + if (!qGuiApp->d_func()->styleHints) + qGuiApp->d_func()->styleHints = new QStyleHints(); + return qGuiApp->d_func()->styleHints; } /*! diff --git a/src/gui/kernel/qguiapplication.h b/src/gui/kernel/qguiapplication.h index 8ae0e6dfc5..75a0f6cd4b 100644 --- a/src/gui/kernel/qguiapplication.h +++ b/src/gui/kernel/qguiapplication.h @@ -126,7 +126,7 @@ public: static inline bool isRightToLeft() { return layoutDirection() == Qt::RightToLeft; } static inline bool isLeftToRight() { return layoutDirection() == Qt::LeftToRight; } - QStyleHints *styleHints() const; + static QStyleHints *styleHints(); static void setDesktopSettingsAware(bool on); static bool desktopSettingsAware(); diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp index ce26b9dd93..3546ce01dd 100644 --- a/src/gui/kernel/qscreen.cpp +++ b/src/gui/kernel/qscreen.cpp @@ -401,7 +401,7 @@ static int log2(uint i) Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation(). */ -int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) +int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const { if (a == Qt::PrimaryOrientation) a = primaryOrientation(); @@ -436,7 +436,7 @@ int QScreen::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation(). */ -QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target) +QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target) const { if (a == Qt::PrimaryOrientation) a = primaryOrientation(); @@ -477,7 +477,7 @@ QTransform QScreen::transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientat Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation(). */ -QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect) +QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect) const { if (a == Qt::PrimaryOrientation) a = primaryOrientation(); @@ -503,7 +503,7 @@ QRect QScreen::mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, cons Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation(). */ -bool QScreen::isPortrait(Qt::ScreenOrientation o) +bool QScreen::isPortrait(Qt::ScreenOrientation o) const { return o == Qt::PortraitOrientation || o == Qt::InvertedPortraitOrientation || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::PortraitOrientation); @@ -515,7 +515,7 @@ bool QScreen::isPortrait(Qt::ScreenOrientation o) Qt::PrimaryOrientation is interpreted as the screen's primaryOrientation(). */ -bool QScreen::isLandscape(Qt::ScreenOrientation o) +bool QScreen::isLandscape(Qt::ScreenOrientation o) const { return o == Qt::LandscapeOrientation || o == Qt::InvertedLandscapeOrientation || (o == Qt::PrimaryOrientation && primaryOrientation() == Qt::LandscapeOrientation); @@ -580,7 +580,7 @@ void QScreenPrivate::updatePrimaryOrientation() safe. This depends on the underlying window system. */ -QPixmap QScreen::grabWindow(WId window, int x, int y, int w, int h) const +QPixmap QScreen::grabWindow(WId window, int x, int y, int w, int h) { const QPlatformScreen *platformScreen = handle(); if (!platformScreen) { diff --git a/src/gui/kernel/qscreen.h b/src/gui/kernel/qscreen.h index 3bd24db3ce..f69e04a595 100644 --- a/src/gui/kernel/qscreen.h +++ b/src/gui/kernel/qscreen.h @@ -118,14 +118,14 @@ public: Qt::ScreenOrientation primaryOrientation() const; Qt::ScreenOrientation orientation() const; - int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b); - QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target); - QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect); + int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const; + QTransform transformBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &target) const; + QRect mapBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b, const QRect &rect) const; - bool isPortrait(Qt::ScreenOrientation orientation); - bool isLandscape(Qt::ScreenOrientation orientation); + bool isPortrait(Qt::ScreenOrientation orientation) const; + bool isLandscape(Qt::ScreenOrientation orientation) const; - QPixmap grabWindow(WId window, int x, int y, int w, int h) const; + QPixmap grabWindow(WId window, int x, int y, int w, int h); Q_SIGNALS: void sizeChanged(const QSize &size); diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h index aacd3ed82f..118e3ec25f 100644 --- a/src/gui/kernel/qwindow.h +++ b/src/gui/kernel/qwindow.h @@ -183,11 +183,6 @@ public: inline QSize size() const { return geometry().size(); } inline QPoint pos() const { return geometry().topLeft(); } -#ifdef QT_DEPRECATED - QT_DEPRECATED inline void move(const QPoint &pt) { setPos(pt); } - QT_DEPRECATED inline void move(int posx, int posy) { setPos(posx, posy); } -#endif - inline void setPos(const QPoint &pt) { setGeometry(QRect(pt, size())); } inline void setPos(int posx, int posy) { setPos(QPoint(posx, posy)); } diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro b/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro index 8bfe6628da..9e59251379 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/qabstractitemmodel.pro @@ -6,4 +6,3 @@ mtdir = ../../../other/modeltest INCLUDEPATH += $$PWD/$${mtdir} SOURCES = tst_qabstractitemmodel.cpp $${mtdir}/dynamictreemodel.cpp $${mtdir}/modeltest.cpp HEADERS = $${mtdir}/dynamictreemodel.h $${mtdir}/modeltest.h -CONFIG += insignificant_test # QTBUG-25325 diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 1e382dde3a..6a6460d17b 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -3666,6 +3666,11 @@ protected: // Chars insert '\0' into the qdebug stream, it is not possible to find a real string length return; } + if (QMetaType::typeFlags(currentId) & QMetaType::PointerToQObject) { + QByteArray currentName = QMetaType::typeName(currentId); + currentName.chop(1); + ok &= (msg.contains(", " + currentName) || msg.contains(", 0x0")); + } ok &= msg.endsWith(") "); QVERIFY2(ok, (QString::fromLatin1("Message is not correctly finished: '") + msg + '\'').toLatin1().constData()); @@ -3694,6 +3699,7 @@ void tst_QVariant::debugStream_data() QTest::newRow("CustomStreamableClass") << QVariant(qMetaTypeId<CustomStreamableClass>(), 0) << qMetaTypeId<CustomStreamableClass>(); QTest::newRow("MyClass") << QVariant(qMetaTypeId<MyClass>(), 0) << qMetaTypeId<MyClass>(); QTest::newRow("InvalidVariant") << QVariant() << int(QMetaType::UnknownType); + QTest::newRow("CustomQObject") << QVariant::fromValue(this) << qMetaTypeId<tst_QVariant*>(); } void tst_QVariant::debugStream() diff --git a/tests/auto/other/modeltest/dynamictreemodel.cpp b/tests/auto/other/modeltest/dynamictreemodel.cpp index 325fc19db2..ab783d0ba2 100644 --- a/tests/auto/other/modeltest/dynamictreemodel.cpp +++ b/tests/auto/other/modeltest/dynamictreemodel.cpp @@ -372,7 +372,17 @@ void ModelChangeChildrenLayoutsCommand::doCommand() } } - foreach (const QModelIndex &idx, m_model->persistentIndexList()) { + // If we're changing one of the parent indexes, we need to ensure that we do that before + // changing any children of that parent. The reason is that we're keeping parent1 and parent2 + // around as QPersistentModelIndex instances, and we query idx.parent() in the loop. + QModelIndexList persistent = m_model->persistentIndexList(); + foreach (const QModelIndex &parent, parents) { + int idx = persistent.indexOf(parent); + if (idx != -1) + persistent.move(idx, 0); + } + + foreach (const QModelIndex &idx, persistent) { if (idx.parent() == parent1) { if (idx.row() == rowSize1 - 1) { m_model->changePersistentIndex(idx, m_model->createIndex(0, idx.column(), idx.internalPointer())); diff --git a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp index 72e2248850..a040a540ed 100644 --- a/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp +++ b/tests/benchmarks/gui/painting/qtracebench/tst_qtracebench.cpp @@ -179,6 +179,7 @@ ReplayWidget::ReplayWidget(const QString &filename_) } QDataStream in(&file); + in.setVersion(QDataStream::Qt_4_7); char *data; uint size; |