diff options
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 19 |
1 files changed, 17 insertions, 2 deletions
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 |