Details
-
Bug
-
Resolution: Won't Do
-
Not Evaluated
-
None
-
5.13.1
-
None
Description
Consider the following cases in Qt 5.13.1:
QString a; // 1, isNull() == true QString b(""); // 2, isNull() == false QString::fromUtf8(""); // 3, isNull() == false QString::fromLatin1(""); // 4, isNull() == false
It seems that QString does dynamic memory allocation in cases 2 and 3 (which are effectively the same cases given the specification of const char* constructor), but not in cases 1 and 4.
- Is there reason to ever allocate for empty string?
- Should fromUtf8() and fromLatin1() behave differently with respect to memory allocation when given empty string?
Technical details:
- fromLatin1(): calls fromLatin1_helper() which in case of zero-sized string calls
d = Data::allocate(0);
Data is a typedef of QStringData (a typedef forQTypedArrayData<ushort> defined in qstringliteral.h), and Data::allocate() returns qt_array_empty (or qt_array_unsharable_empty) given the zero-valued parameter.
- fromUtf8(): calls fromUtf8_helper() -> QUtf8::convertToUnicode("", 0) -> QString result(0, Qt::Uninitialized); -> d = Data::allocate(0 + 1);