summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydatapointer.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2019-11-19 14:21:10 +0100
committerLars Knoll <lars.knoll@qt.io>2020-07-06 21:30:06 +0200
commita46caf087ca70a7482e065defa4d9547ae1335bd (patch)
tree4d112d89cdf9d57f5749ff0cbc638551f70d0caa /src/corelib/tools/qarraydatapointer.h
parent76004502baa118016c8e0f32895af7a822f1ba37 (diff)
Simplify Q_ARRAY_LITERAL
And clean up some unused pieces of code. Change-Id: I285b6862dc67b7130af66d3e08f652b1a56b990e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydatapointer.h')
-rw-r--r--src/corelib/tools/qarraydatapointer.h19
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