summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/doc/src/containers.qdoc23
-rw-r--r--src/corelib/global/qglobal.cpp13
2 files changed, 33 insertions, 3 deletions
diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc
index 9cda3f91d8..4a5de26f14 100644
--- a/src/corelib/doc/src/containers.qdoc
+++ b/src/corelib/doc/src/containers.qdoc
@@ -527,6 +527,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
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 62ca2ca8a1..bcfc6ada2e 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -3995,12 +3995,19 @@ bool qunsetenv(const char *varName)
pattern still represents a valid object, and memcpy() can be used
to create a valid independent copy of a QUuid object.
- Example of a movable type:
+ Example of a relocatable type:
\snippet code/src_corelib_global_qglobal.cpp 39
- Qt will try to detect the class of a type using std::is_trivial or
- std::is_trivially_copyable. Use this macro to tune the behavior.
+ Qt will try to detect the class of a type using
+ \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.
+ Use this macro to tune the behavior.
For instance many types would be candidates for Q_RELOCATABLE_TYPE despite
not being trivially-copyable.
*/