diff options
-rw-r--r-- | src/corelib/text/qstring.cpp | 2 | ||||
-rw-r--r-- | src/corelib/tools/qarraydata.h | 43 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 19 | ||||
-rw-r--r-- | src/corelib/tools/qlist.qdoc | 5 | ||||
-rw-r--r-- | src/gui/painting/webgradients.cpp | 2 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qarraydata/simplevector.h | 13 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp | 31 | ||||
-rw-r--r-- | util/gradientgen/gradientgen.cpp | 2 |
8 files changed, 21 insertions, 96 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp index af3be9ab9f..985c00ae6b 100644 --- a/src/corelib/text/qstring.cpp +++ b/src/corelib/text/qstring.cpp @@ -8619,7 +8619,7 @@ bool QString::isRightToLeft() const */ QString QString::fromRawData(const QChar *unicode, int size) { - return QString(Data::fromRawData(const_cast<char16_t *>(reinterpret_cast<const char16_t *>(unicode)), size)); + return QString(DataPointer::fromRawData(const_cast<char16_t *>(reinterpret_cast<const char16_t *>(unicode)), size)); } /*! diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index d0a285a0e9..c921e4eaa5 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -165,23 +165,6 @@ struct Q_CORE_EXPORT QArrayData Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::ArrayOptions) -template <class T, size_t N> -struct QStaticArrayData -{ - // static arrays are of type RawDataType - QArrayData header; - T data[N]; -}; - -// Support for returning QArrayDataPointer<T> from functions -template <class T> -struct QArrayDataPointerRef -{ - QTypedArrayData<T> *ptr; - T *data; - uint size; -}; - template <class T> struct QTypedArrayData : QArrayData @@ -218,34 +201,8 @@ struct QTypedArrayData static_assert(sizeof(QTypedArrayData) == sizeof(QArrayData)); QArrayData::deallocate(data, sizeof(T), alignof(AlignmentDummy)); } - - static QArrayDataPointerRef<T> fromRawData(const T *data, size_t n) - { - static_assert(sizeof(QTypedArrayData) == sizeof(QArrayData)); - QArrayDataPointerRef<T> result = { - nullptr, const_cast<T *>(data), uint(n) - }; - return result; - } }; -//////////////////////////////////////////////////////////////////////////////// -// Q_ARRAY_LITERAL - -// The idea here is to place a (read-only) copy of header and array data in an -// mmappable portion of the executable (typically, .rodata section). This is -// accomplished by hiding a static const instance of QStaticArrayData, which is -// POD. - -// Hide array inside a lambda -#define Q_ARRAY_LITERAL(Type, ...) \ - ([]() -> QArrayDataPointerRef<Type> { \ - static Type const data[] = { __VA_ARGS__ }; \ - enum { Size = sizeof(data) / sizeof(data[0]) }; \ - return { nullptr, const_cast<Type *>(data), Size }; \ - }()) - /**/ - namespace QtPrivate { struct Q_CORE_EXPORT QContainerImplHelper { diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index a8b472c9bf..8e30373211 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -81,9 +81,10 @@ public: Q_CHECK_PTR(d); } - QArrayDataPointer(QArrayDataPointerRef<T> dd) noexcept - : d(dd.ptr), ptr(dd.data), size(dd.size) + static QArrayDataPointer fromRawData(const T *rawData, size_t length) { + Q_ASSERT(rawData || !length); + return { nullptr, const_cast<T *>(rawData), length }; } QArrayDataPointer &operator=(const QArrayDataPointer &other) noexcept @@ -235,6 +236,20 @@ inline void qSwap(QArrayDataPointer<T> &p1, QArrayDataPointer<T> &p2) noexcept p1.swap(p2); } +//////////////////////////////////////////////////////////////////////////////// +// Q_ARRAY_LITERAL + +// The idea here is to place a (read-only) copy of header and array data in an +// mmappable portion of the executable (typically, .rodata section). + +// Hide array inside a lambda +#define Q_ARRAY_LITERAL(Type, ...) \ + ([]() -> QArrayDataPointer<Type> { \ + static Type const data[] = { __VA_ARGS__ }; \ + return QArrayDataPointer<Type>::fromRawData(const_cast<Type *>(data), std::size(data)); \ + }()) +/**/ + QT_END_NAMESPACE #endif // include guard diff --git a/src/corelib/tools/qlist.qdoc b/src/corelib/tools/qlist.qdoc index 1a94bf4315..550663ed0e 100644 --- a/src/corelib/tools/qlist.qdoc +++ b/src/corelib/tools/qlist.qdoc @@ -267,11 +267,6 @@ The value type of \c InputIterator must be convertible to \c T. */ -/*! - \fn template <typename T> QList<T>::QList(QArrayDataPointerRef<T> ref) - \internal -*/ - /*! \fn template <typename T> QList<T>::~QList() Destroys the list. diff --git a/src/gui/painting/webgradients.cpp b/src/gui/painting/webgradients.cpp index b4d297450b..33bbcc4319 100644 --- a/src/gui/painting/webgradients.cpp +++ b/src/gui/painting/webgradients.cpp @@ -39,7 +39,7 @@ // This file is auto-generated by gradientgen. DO NOT EDIT! -static QArrayDataPointerRef<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset) +static QList<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset) { Q_ASSERT(preset < QGradient::NumPresets); switch (preset) { diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h index 1a9ed35b7a..8109c463a3 100644 --- a/tests/auto/corelib/tools/qarraydata/simplevector.h +++ b/tests/auto/corelib/tools/qarraydata/simplevector.h @@ -71,17 +71,6 @@ public: d->copyAppend(begin, end); } - SimpleVector(QArrayDataPointerRef<T> ptr) - : d(ptr) - { - } - - template <size_t N> - explicit SimpleVector(QStaticArrayData<T, N> &ptr) - : d(static_cast<Data *>(&ptr.header), ptr.data, N) - { - } - SimpleVector(Data *header, T *data, size_t len = 0) : d(header, data, len) { @@ -340,7 +329,7 @@ public: static SimpleVector fromRawData(const T *data, size_t size) { - return SimpleVector(Data::fromRawData(data, size)); + return SimpleVector({ nullptr, const_cast<T *>(data), size }); } private: diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp index 128bc51553..5be774cc53 100644 --- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp +++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp @@ -1241,22 +1241,6 @@ void tst_QArrayData::literals() QCOMPARE(d.data()[i], wchar_t('A' + i)); } - { - SimpleVector<char> v = Q_ARRAY_LITERAL(char, "ABCDEFGHIJ"); - - QVERIFY(!v.isNull()); - QVERIFY(!v.isEmpty()); - QCOMPARE(v.size(), size_t(11)); - // v.capacity() is unspecified, for now - - QVERIFY(v.isStatic()); - QCOMPARE((void*)(const char*)(v.constBegin() + v.size()), (void*)(const char*)v.constEnd()); - - for (int i = 0; i < 10; ++i) - QCOMPARE(const_(v)[i], char('A' + i)); - QCOMPARE(const_(v)[10], char('\0')); - } - struct LiteralType { int value; Q_DECL_CONSTEXPR LiteralType(int v = 0) : value(v) {} @@ -1313,21 +1297,6 @@ void tst_QArrayData::variadicLiterals() QCOMPARE(d.data()[i][1], '\0'); } } - - { - SimpleVector<int> v = Q_ARRAY_LITERAL(int, 0, 1, 2, 3, 4, 5, 6); - - QVERIFY(!v.isNull()); - QVERIFY(!v.isEmpty()); - QCOMPARE(v.size(), size_t(7)); - // v.capacity() is unspecified, for now - - QVERIFY(v.isStatic()); - QCOMPARE((const int *)(v.constBegin() + v.size()), (const int *)v.constEnd()); - - for (int i = 0; i < 7; ++i) - QCOMPARE(const_(v)[i], i); - } } // std::remove_reference is in C++11, but requires library support diff --git a/util/gradientgen/gradientgen.cpp b/util/gradientgen/gradientgen.cpp index 5dc0b53b9d..bd89ae7383 100644 --- a/util/gradientgen/gradientgen.cpp +++ b/util/gradientgen/gradientgen.cpp @@ -264,7 +264,7 @@ int main() p.printLine("// This file is auto-generated by gradientgen. DO NOT EDIT!"); p.printLine(); - p.printLine("static QArrayDataPointerRef<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset)"); + p.printLine("static QList<QGradientStop> qt_preset_gradient_stops(QGradient::Preset preset)"); p.printLine("{"); { Printer::Indenter i(p); |