summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-08 17:05:29 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-05-14 14:19:47 +0200
commit594abde1a257a95ef33634a950a6429ac33d2b76 (patch)
tree8ab4ee79cd6147b5d9cce481d9fdbc98920a5b72 /src
parentaf3caa2271f47ddf48da46a0cc5932aaa442eb39 (diff)
Enforce that statically allocated array-like containers have 0 capacity
It has been the case for both QStringLiteral and QByteArrayLiteral since Qt 5.0, and Q_ARRAY_LITERAL since Qt 6.0. Since it's definitely surprising, add a note in the docs, which is "somehow" consistent with the interpretation of capacity as the biggest possible size before we reallocate. Since it's 0, any manipulation of the size will cause a reallocation. (Alternatively: the capacity() is for how many elements memory was requested from the free store. No memory was allocated, so 0...) Task-number: QTBUG-84069 Change-Id: I5c7d21a22d1bd8b8d9b71143e33d537ca0224acd Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/text/qbytearray.cpp3
-rw-r--r--src/corelib/text/qstring.cpp3
-rw-r--r--src/corelib/tools/qvector.qdoc3
3 files changed, 9 insertions, 0 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp
index 8d70955065..32642b83e3 100644
--- a/src/corelib/text/qbytearray.cpp
+++ b/src/corelib/text/qbytearray.cpp
@@ -1281,6 +1281,9 @@ QByteArray &QByteArray::operator=(const char *str)
ever need to call this function. If you want to know how many
bytes are in the byte array, call size().
+ \note a statically allocated byte array will report a capacity of 0,
+ even if it's not empty.
+
\sa reserve(), squeeze()
*/
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index b70e2a3ed2..1e227a09ba 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -2283,6 +2283,9 @@ void QString::resize(int size, QChar fillChar)
need to call this function. If you want to know how many
characters are in the string, call size().
+ \note a statically allocated string will report a capacity of 0,
+ even if it's not empty.
+
\sa reserve(), squeeze()
*/
diff --git a/src/corelib/tools/qvector.qdoc b/src/corelib/tools/qvector.qdoc
index cbb118ddb9..88baaab8c1 100644
--- a/src/corelib/tools/qvector.qdoc
+++ b/src/corelib/tools/qvector.qdoc
@@ -438,6 +438,9 @@
need to call this function. If you want to know how many items are
in the vector, call size().
+ \note a statically allocated vector will report a capacity of 0,
+ even if it's not empty.
+
\sa reserve(), squeeze()
*/