summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/src
diff options
context:
space:
mode:
authorAndreas Buhr <andreas.buhr@qt.io>2020-11-17 16:36:02 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-12-03 15:09:12 +0000
commit0902ff112e7167d29c00838672497c755c1051b4 (patch)
treede314e334db1bd9487aff5ee58208c13b470d75e /src/corelib/doc/src
parent2537b5c6c34a360f943fd79327eee7a7ba6c3fc8 (diff)
Extend container overview documentation, mention Q_DECLARE_TYPEINFO
The container overview documentation did not mention Q_DECLARE_TYPEINFO and the related optimizations. This patch adds a short paragraph about it. Task-number: QTBUG-86584 Change-Id: I5b0b8ce92a47da5f0398cc413fbf3e07b0921e59 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> (cherry picked from commit d545fbb61b699802e9ae1a3c19f4c4bef724fbda) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib/doc/src')
-rw-r--r--src/corelib/doc/src/containers.qdoc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc
index 84cde51a17..c5b70c2675 100644
--- a/src/corelib/doc/src/containers.qdoc
+++ b/src/corelib/doc/src/containers.qdoc
@@ -474,6 +474,29 @@
with the expected number of items before you insert the items.
The next section discusses this topic in more depth.
+ \section1 Optimizations for Primitive and Relocatable Types
+
+ Qt containers can use optimized code paths if the stored
+ elements are relocatable or even primitive.
+ However, whether types are primitive or relocatable
+ cannot be detected in all cases.
+ You can declare your types to be primitive or relocatable
+ by using the Q_DECLARE_TYPEINFO macro with the Q_PRIMITIVE_TYPE
+ flag or the Q_RELOCATABLE_TYPE flag. See the documentation
+ of Q_DECLARE_TYPEINFO for further details and usage examples.
+
+ If you do not use Q_DECLARE_TYPEINFO,
+ Qt will use
+ \l {https://en.cppreference.com/w/cpp/types/is_trivial} {std::is_trivial_v<T>}
+ to indentify primitive
+ types and it will require both
+ \l {https://en.cppreference.com/w/cpp/types/is_trivially_copyable} {std::is_trivially_copyable_v<T>}
+ and
+ \l {https://en.cppreference.com/w/cpp/types/is_destructible} {std::is_trivially_destructible_v<T>}
+ to identify relocatable types.
+ This is always a safe choice, albeit
+ of maybe suboptimal performance.
+
\section1 Growth Strategies
QList<T>, QString, and QByteArray store their items