From 56ddd1947ac5f4311e788b9202210f86ebce1a07 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 22 Jun 2014 11:57:21 -0700 Subject: [PATCH] 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: Nikolai Kosjar --- src/plugins/cpptools/stringtable.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plugins/cpptools/stringtable.cpp b/src/plugins/cpptools/stringtable.cpp index 9617430d4a2..b5acd3f5d0f 100644 --- a/src/plugins/cpptools/stringtable.cpp +++ b/src/plugins/cpptools/stringtable.cpp @@ -29,6 +29,8 @@ #include "stringtable.h" +#include + #include #include #include @@ -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(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(string).data_ptr()->ref.atomic.load(); + QArrayData *data_ptr = const_cast(string).data_ptr(); + return data_ptr->ref.isShared() || data_ptr->ref.isStatic(); #else - return const_cast(string).data_ptr()->ref; + return const_cast(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;