summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/stringtable.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2014-06-22 11:57:21 -0700
committerThiago Macieira <thiago.macieira@intel.com>2014-07-01 20:58:14 +0200
commit56ddd1947ac5f4311e788b9202210f86ebce1a07 (patch)
tree3f43d83fac1070f2a89b0b16da0835ddcb07a24d /src/plugins/cpptools/stringtable.cpp
parenta355013eb17ec8cc0b726f3e0a846ed39fc8ffd2 (diff)
downloadqt-creator-56ddd1947ac5f4311e788b9202210f86ebce1a07.tar.gz
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 <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/stringtable.cpp')
-rw-r--r--src/plugins/cpptools/stringtable.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/plugins/cpptools/stringtable.cpp b/src/plugins/cpptools/stringtable.cpp
index 9617430d4a..b5acd3f5d0 100644
--- a/src/plugins/cpptools/stringtable.cpp
+++ b/src/plugins/cpptools/stringtable.cpp
@@ -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;