StringTable: Fix isQStringInUse()

With the current implementation it always returns true, even when
there is only one existing copy of a string inside m_strings set,
without any reference. This is due to creating a copy of the
QArrayDataPointer:

1 QArrayData::ref / qarraydata.h
2 QArrayDataPointer<char16_t>::ref / qarraydatapointer.h 438
3 QArrayDataPointer<char16_t>::QArrayDataPointer / qarraydatapointer.h 40
4 isQStringInUse

So, the ref_ is always at least 2.

Avoid creating a copy by taking a reference instead.

Observed misbehavior: After switching session nothing is erased from
the m_strings, it cumulates indefinitely instead.

Task-number: QTCREATORBUG-18800
Change-Id: I17981d44f88307e736ec03380baa39a03f0719bf
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Jarek Kobus
2025-02-03 18:18:44 +01:00
parent bc84cd209d
commit ec65481b54

View File

@@ -103,7 +103,7 @@ static int bytesSaved = 0;
static inline bool isQStringInUse(const QString &string)
{
QStringPrivate data_ptr = const_cast<QString&>(string).data_ptr();
QStringPrivate &data_ptr = const_cast<QString&>(string).data_ptr();
if (DebugStringTable) {
const int ref = data_ptr->d_ptr()->ref_;
bytesSaved += (ref - 1) * string.size();