Commit 56ddd194 authored by Thiago Macieira's avatar Thiago Macieira

Use the functions in QRefCount to check if the QString is in use

QStringLiteral() returns a string that has a refcount of -1 and it must
be kept. There is no way to determine if it's still in use, so we'll
just assume it is. Any QStringLiteral inserted into the structure will
stay there forever.

On the other hand, we must not accept unsharable strings, so Q_ASSERT on
that.

Change-Id: I5fbdc1046f0f00319f27fdfb7aa3ff87371ea668
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent a355013e
......@@ -29,6 +29,8 @@
#include "stringtable.h"
#include <utils/qtcassert.h>
#include <QDebug>
#include <QThreadPool>
#include <QTime>
......@@ -58,6 +60,9 @@ QString StringTable::insert(const QString &string)
if (string.isEmpty())
return string;
#if QT_VERSION >= 0x050000 && QT_SUPPORTS(UNSHARABLE_CONTAINERS)
QTC_ASSERT(const_cast<QString&>(string).data_ptr()->ref.isSharable(), return string);
#endif
m_stopGCRequested.fetchAndStoreAcquire(true);
......@@ -83,12 +88,13 @@ enum {
DebugStringTable = 0
};
static inline int qstringRefCount(const QString &string)
static inline bool isQStringInUse(const QString &string)
{
#if QT_VERSION >= 0x050000
return const_cast<QString&>(string).data_ptr()->ref.atomic.load();
QArrayData *data_ptr = const_cast<QString&>(string).data_ptr();
return data_ptr->ref.isShared() || data_ptr->ref.isStatic();
#else
return const_cast<QString&>(string).data_ptr()->ref;
return const_cast<QString&>(string).data_ptr()->ref != 1;
#endif
}
......@@ -108,7 +114,7 @@ void StringTable::GC()
if (m_stopGCRequested.testAndSetRelease(true, false))
return;
if (qstringRefCount(*i) == 1)
if (!isQStringInUse(*i))
i = m_strings.erase(i);
else
++i;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment