forked from qt-creator/qt-creator
CppTools: Apply 'static' pattern to StringTable
This also fixes a crash on loading (some?) projects introduced
in 577bf7c08a
.
Change-Id: Ie35d466fa3b84b183118fe93f55393a4c59755de
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -277,7 +277,7 @@ public:
|
||||
future.setProgressValue(0);
|
||||
int progress = 0;
|
||||
|
||||
SearchSymbols search(CppToolsPlugin::stringTable());
|
||||
SearchSymbols search;
|
||||
search.setSymbolsToSearchFor(m_parameters.types);
|
||||
CPlusPlus::Snapshot::const_iterator it = m_snapshot.begin();
|
||||
|
||||
|
@@ -37,10 +37,8 @@
|
||||
using namespace CppTools::Internal;
|
||||
using namespace CPlusPlus;
|
||||
|
||||
CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppTools::CppModelManager *manager,
|
||||
StringTable &stringTable)
|
||||
CppCurrentDocumentFilter::CppCurrentDocumentFilter(CppTools::CppModelManager *manager)
|
||||
: m_modelManager(manager)
|
||||
, search(stringTable)
|
||||
{
|
||||
setId(Constants::CURRENT_DOCUMENT_FILTER_ID);
|
||||
setDisplayName(Constants::CURRENT_DOCUMENT_FILTER_DISPLAY_NAME);
|
||||
|
@@ -42,8 +42,7 @@ class CppCurrentDocumentFilter : public Core::ILocatorFilter
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CppCurrentDocumentFilter(CppModelManager *manager,
|
||||
StringTable &stringTable);
|
||||
explicit CppCurrentDocumentFilter(CppModelManager *manager);
|
||||
~CppCurrentDocumentFilter() {}
|
||||
|
||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
|
@@ -24,7 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "cpplocatordata.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace CppTools::Internal;
|
||||
@@ -32,9 +32,7 @@ using namespace CppTools::Internal;
|
||||
enum { MaxPendingDocuments = 10 };
|
||||
|
||||
CppLocatorData::CppLocatorData()
|
||||
: m_strings(&CppToolsPlugin::stringTable())
|
||||
, m_search(CppToolsPlugin::stringTable())
|
||||
, m_pendingDocumentsMutex(QMutex::Recursive)
|
||||
: m_pendingDocumentsMutex(QMutex::Recursive)
|
||||
{
|
||||
m_search.setSymbolsToSearchFor(SymbolSearcher::Enums |
|
||||
SymbolSearcher::Classes |
|
||||
@@ -79,7 +77,7 @@ void CppLocatorData::onAboutToRemoveFiles(const QStringList &files)
|
||||
}
|
||||
}
|
||||
|
||||
m_strings->scheduleGC();
|
||||
StringTable::scheduleGC();
|
||||
flushPendingDocument(false);
|
||||
}
|
||||
|
||||
@@ -93,7 +91,7 @@ void CppLocatorData::flushPendingDocument(bool force) const
|
||||
return;
|
||||
|
||||
foreach (CPlusPlus::Document::Ptr doc, m_pendingDocuments)
|
||||
m_infosByFile.insert(findOrInsertFilePath(doc->fileName()), m_search(doc));
|
||||
m_infosByFile.insert(StringTable::insert(doc->fileName()), m_search(doc));
|
||||
|
||||
m_pendingDocuments.clear();
|
||||
m_pendingDocuments.reserve(MaxPendingDocuments);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "cpptools_global.h"
|
||||
#include "cppmodelmanager.h"
|
||||
#include "searchsymbols.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
|
||||
@@ -64,12 +63,6 @@ private:
|
||||
void flushPendingDocument(bool force) const;
|
||||
QList<IndexItem::Ptr> allIndexItems(const QHash<QString, QList<IndexItem::Ptr>> &items) const;
|
||||
|
||||
QString findOrInsertFilePath(const QString &path) const
|
||||
{ return m_strings->insert(path); }
|
||||
|
||||
private:
|
||||
Internal::StringTable *m_strings = nullptr; // Used to avoid QString duplication
|
||||
|
||||
mutable SearchSymbols m_search;
|
||||
mutable QHash<QString, IndexItem::Ptr> m_infosByFile;
|
||||
|
||||
|
@@ -41,10 +41,11 @@
|
||||
#include "cpprefactoringchanges.h"
|
||||
#include "cpprefactoringengine.h"
|
||||
#include "cppsourceprocessor.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsplugin.h"
|
||||
#include "cpptoolsconstants.h"
|
||||
#include "cpptoolsreuse.h"
|
||||
#include "editordocumenthandle.h"
|
||||
#include "stringtable.h"
|
||||
#include "symbolfinder.h"
|
||||
#include "symbolsfindfilter.h"
|
||||
#include "followsymbolinterface.h"
|
||||
@@ -442,16 +443,15 @@ void CppModelManager::resetFilters()
|
||||
setCurrentDocumentFilter();
|
||||
}
|
||||
|
||||
void CppModelManager::createCppModelManager(Internal::CppToolsPlugin *parent,
|
||||
Internal::StringTable &stringTable)
|
||||
void CppModelManager::createCppModelManager(Internal::CppToolsPlugin *parent)
|
||||
{
|
||||
QTC_ASSERT(!m_instance, return;);
|
||||
m_instance = new CppModelManager();
|
||||
m_instance->initCppTools(stringTable);
|
||||
m_instance->initCppTools();
|
||||
m_instance->setParent(parent);
|
||||
}
|
||||
|
||||
void CppModelManager::initCppTools(Internal::StringTable &stringTable)
|
||||
void CppModelManager::initCppTools()
|
||||
{
|
||||
// Objects
|
||||
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged,
|
||||
@@ -477,7 +477,7 @@ void CppModelManager::initCppTools(Internal::StringTable &stringTable)
|
||||
setFunctionsFilter(std::make_unique<CppFunctionsFilter>(&d->m_locatorData));
|
||||
setSymbolsFindFilter(std::make_unique<SymbolsFindFilter>(this));
|
||||
setCurrentDocumentFilter(
|
||||
std::make_unique<Internal::CppCurrentDocumentFilter>(this, stringTable));
|
||||
std::make_unique<Internal::CppCurrentDocumentFilter>(this));
|
||||
}
|
||||
|
||||
void CppModelManager::initializeBuiltinModelManagerSupport()
|
||||
|
@@ -31,7 +31,6 @@
|
||||
#include "projectinfo.h"
|
||||
#include "projectpart.h"
|
||||
#include "projectpartheaderpath.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
#include <cplusplus/cppmodelmanagerbase.h>
|
||||
#include <coreplugin/find/ifindfilter.h>
|
||||
@@ -94,8 +93,7 @@ public:
|
||||
~CppModelManager();
|
||||
|
||||
static CppModelManager *instance();
|
||||
static void createCppModelManager(Internal::CppToolsPlugin *parent,
|
||||
Internal::StringTable &stringTable);
|
||||
static void createCppModelManager(Internal::CppToolsPlugin *parent);
|
||||
|
||||
// Documented in source file.
|
||||
enum ProgressNotificationMode {
|
||||
@@ -273,7 +271,7 @@ private:
|
||||
ProjectExplorer::Macros internalDefinedMacros() const;
|
||||
|
||||
void dumpModelManagerConfiguration(const QString &logFileId);
|
||||
void initCppTools(Internal::StringTable &stringTable);
|
||||
void initCppTools();
|
||||
void resetFilters();
|
||||
|
||||
private:
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "cppprojectfile.h"
|
||||
#include "cpptoolsbridge.h"
|
||||
#include "projectinfo.h"
|
||||
#include "stringtable.h"
|
||||
#include "cpptoolsbridgeqtcreatorimplementation.h"
|
||||
|
||||
#include <coreplugin/actionmanager/actioncontainer.h>
|
||||
@@ -74,13 +75,14 @@ enum { debug = 0 };
|
||||
static CppToolsPlugin *m_instance = nullptr;
|
||||
static QHash<QString, QString> m_headerSourceMapping;
|
||||
|
||||
class CppToolsPluginPluginPrivate
|
||||
class CppToolsPluginPrivate
|
||||
{
|
||||
public:
|
||||
CppToolsPluginPluginPrivate()
|
||||
CppToolsPluginPrivate()
|
||||
: m_codeModelSettings(new CppCodeModelSettings)
|
||||
{
|
||||
CppModelManager::createCppModelManager(m_instance, m_stringTable);
|
||||
StringTable::initialize();
|
||||
CppModelManager::createCppModelManager(m_instance);
|
||||
m_settings = new CppToolsSettings(m_instance); // force registration of cpp tools settings
|
||||
m_codeModelSettings->fromSettings(ICore::settings());
|
||||
m_cppFileSettingsPage = new CppFileSettingsPage(m_instance->m_fileSettings);
|
||||
@@ -88,8 +90,9 @@ public:
|
||||
m_cppCodeStyleSettingsPage = new CppCodeStyleSettingsPage;
|
||||
}
|
||||
|
||||
~CppToolsPluginPluginPrivate()
|
||||
~CppToolsPluginPrivate()
|
||||
{
|
||||
StringTable::destroy();
|
||||
delete m_cppFileSettingsPage;
|
||||
delete m_cppCodeModelSettingsPage;
|
||||
delete m_cppCodeStyleSettingsPage;
|
||||
@@ -97,7 +100,6 @@ public:
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> m_codeModelSettings;
|
||||
CppToolsSettings *m_settings = nullptr;
|
||||
StringTable m_stringTable;
|
||||
CppFileSettingsPage *m_cppFileSettingsPage = nullptr;
|
||||
CppCodeModelSettingsPage *m_cppCodeModelSettingsPage = nullptr;
|
||||
CppCodeStyleSettingsPage *m_cppCodeStyleSettingsPage = nullptr;
|
||||
@@ -163,7 +165,7 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
Q_UNUSED(arguments)
|
||||
Q_UNUSED(error)
|
||||
|
||||
d = new CppToolsPluginPluginPrivate;
|
||||
d = new CppToolsPluginPrivate;
|
||||
|
||||
JsExpander::registerQObjectForJs(QLatin1String("Cpp"), new CppToolsJsExtension);
|
||||
|
||||
@@ -219,11 +221,6 @@ QSharedPointer<CppCodeModelSettings> CppToolsPlugin::codeModelSettings() const
|
||||
return d->m_codeModelSettings;
|
||||
}
|
||||
|
||||
StringTable &CppToolsPlugin::stringTable()
|
||||
{
|
||||
return m_instance->d->m_stringTable;
|
||||
}
|
||||
|
||||
void CppToolsPlugin::switchHeaderSource()
|
||||
{
|
||||
CppTools::switchHeaderSource();
|
||||
|
@@ -26,7 +26,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "cpptools_global.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
#include <projectexplorer/projectexplorer.h>
|
||||
|
||||
@@ -47,7 +46,7 @@ class CppCodeModelSettings;
|
||||
namespace Internal {
|
||||
|
||||
struct CppFileSettings;
|
||||
class CppToolsPluginPluginPrivate;
|
||||
class CppToolsPluginPrivate;
|
||||
|
||||
class CppToolsPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
@@ -72,8 +71,6 @@ public:
|
||||
|
||||
QSharedPointer<CppCodeModelSettings> codeModelSettings() const;
|
||||
|
||||
static StringTable &stringTable();
|
||||
|
||||
public slots:
|
||||
void switchHeaderSource();
|
||||
void switchHeaderSourceInNextSplit();
|
||||
@@ -180,8 +177,8 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
friend class CppToolsPluginPluginPrivate;
|
||||
CppToolsPluginPluginPrivate *d = nullptr;
|
||||
friend class CppToolsPluginPrivate;
|
||||
CppToolsPluginPrivate *d = nullptr;
|
||||
QSharedPointer<CppFileSettings> m_fileSettings;
|
||||
};
|
||||
|
||||
|
@@ -24,6 +24,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "searchsymbols.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
#include <cplusplus/Icons.h>
|
||||
#include <cplusplus/LookupContext.h>
|
||||
@@ -45,9 +46,8 @@ SearchSymbols::SymbolTypes SearchSymbols::AllTypes =
|
||||
| SymbolSearcher::Enums
|
||||
| SymbolSearcher::Declarations;
|
||||
|
||||
SearchSymbols::SearchSymbols(Internal::StringTable &stringTable)
|
||||
: strings(stringTable)
|
||||
, symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums)
|
||||
SearchSymbols::SearchSymbols()
|
||||
: symbolsToSearchFor(SymbolSearcher::Classes | SymbolSearcher::Functions | SymbolSearcher::Enums)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ void SearchSymbols::setSymbolsToSearchFor(const SymbolTypes &types)
|
||||
|
||||
IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope)
|
||||
{
|
||||
IndexItem::Ptr root = IndexItem::create(findOrInsert(doc->fileName()), 100);
|
||||
IndexItem::Ptr root = IndexItem::create(Internal::StringTable::insert(doc->fileName()), 100);
|
||||
|
||||
{ // RAII scope
|
||||
ScopedIndexItemPtr parentRaii(_parent, root);
|
||||
@@ -67,13 +67,13 @@ IndexItem::Ptr SearchSymbols::operator()(Document::Ptr doc, const QString &scope
|
||||
|
||||
QTC_ASSERT(_parent, return IndexItem::Ptr());
|
||||
QTC_ASSERT(root, return IndexItem::Ptr());
|
||||
QTC_ASSERT(_parent->fileName() == findOrInsert(doc->fileName()),
|
||||
QTC_ASSERT(_parent->fileName() == Internal::StringTable::insert(doc->fileName()),
|
||||
return IndexItem::Ptr());
|
||||
|
||||
for (unsigned i = 0, ei = doc->globalSymbolCount(); i != ei; ++i)
|
||||
accept(doc->globalSymbolAt(i));
|
||||
|
||||
strings.scheduleGC();
|
||||
Internal::StringTable::scheduleGC();
|
||||
m_paths.clear();
|
||||
}
|
||||
|
||||
@@ -294,11 +294,12 @@ IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QStr
|
||||
}
|
||||
|
||||
const QIcon icon = Icons::iconForSymbol(symbol);
|
||||
IndexItem::Ptr newItem = IndexItem::create(findOrInsert(symbolName),
|
||||
findOrInsert(symbolType),
|
||||
findOrInsert(symbolScope),
|
||||
|
||||
IndexItem::Ptr newItem = IndexItem::create(Internal::StringTable::insert(symbolName),
|
||||
Internal::StringTable::insert(symbolType),
|
||||
Internal::StringTable::insert(symbolScope),
|
||||
itemType,
|
||||
findOrInsert(path),
|
||||
Internal::StringTable::insert(path),
|
||||
symbol->line(),
|
||||
symbol->column() - 1, // 1-based vs 0-based column
|
||||
icon);
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#include "cpptools_global.h"
|
||||
#include "cppindexingsupport.h"
|
||||
#include "indexitem.h"
|
||||
#include "stringtable.h"
|
||||
|
||||
#include <cplusplus/CppDocument.h>
|
||||
#include <cplusplus/Overview.h>
|
||||
@@ -46,7 +45,7 @@ public:
|
||||
|
||||
static SymbolTypes AllTypes;
|
||||
|
||||
SearchSymbols(Internal::StringTable &stringTable);
|
||||
SearchSymbols();
|
||||
|
||||
void setSymbolsToSearchFor(const SymbolTypes &types);
|
||||
|
||||
@@ -98,11 +97,6 @@ private:
|
||||
template<class T> void processFunction(T *func);
|
||||
|
||||
private:
|
||||
QString findOrInsert(const QString &s)
|
||||
{ return strings.insert(s); }
|
||||
|
||||
Internal::StringTable &strings; // Used to avoid QString duplication
|
||||
|
||||
IndexItem::Ptr _parent;
|
||||
QString _scope;
|
||||
CPlusPlus::Overview overview;
|
||||
|
@@ -28,8 +28,11 @@
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMutex>
|
||||
#include <QSet>
|
||||
#include <QThreadPool>
|
||||
#include <QTime>
|
||||
#include <QTimer>
|
||||
|
||||
using namespace CppTools::Internal;
|
||||
|
||||
@@ -37,9 +40,37 @@ enum {
|
||||
GCTimeOut = 10 * 1000 // 10 seconds
|
||||
};
|
||||
|
||||
StringTable::StringTable()
|
||||
enum {
|
||||
DebugStringTable = 0
|
||||
};
|
||||
|
||||
class StringTablePrivate : public QObject
|
||||
{
|
||||
public:
|
||||
StringTablePrivate();
|
||||
|
||||
QString insert(const QString &string);
|
||||
void startGC() { QThreadPool::globalInstance()->start(&m_gcRunner); }
|
||||
void GC();
|
||||
|
||||
class GCRunner: public QRunnable {
|
||||
StringTablePrivate &m_stringTable;
|
||||
|
||||
public:
|
||||
GCRunner(StringTablePrivate &stringTable): m_stringTable(stringTable) {}
|
||||
virtual void run() { m_stringTable.GC(); }
|
||||
} m_gcRunner;
|
||||
|
||||
mutable QMutex m_lock;
|
||||
QAtomicInt m_stopGCRequested{false};
|
||||
QSet<QString> m_strings;
|
||||
QTimer m_gcCountDown;
|
||||
};
|
||||
|
||||
static StringTablePrivate *m_instance = nullptr;
|
||||
|
||||
StringTablePrivate::StringTablePrivate()
|
||||
: m_gcRunner(*this)
|
||||
, m_stopGCRequested(false)
|
||||
{
|
||||
m_strings.reserve(1000);
|
||||
|
||||
@@ -48,10 +79,15 @@ StringTable::StringTable()
|
||||
m_gcCountDown.setObjectName(QLatin1String("StringTable::m_gcCountDown"));
|
||||
m_gcCountDown.setSingleShot(true);
|
||||
m_gcCountDown.setInterval(GCTimeOut);
|
||||
connect(&m_gcCountDown, &QTimer::timeout, this, &StringTable::startGC);
|
||||
connect(&m_gcCountDown, &QTimer::timeout, this, &StringTablePrivate::startGC);
|
||||
}
|
||||
|
||||
QString StringTable::insert(const QString &string)
|
||||
{
|
||||
return m_instance->insert(string);
|
||||
}
|
||||
|
||||
QString StringTablePrivate::insert(const QString &string)
|
||||
{
|
||||
if (string.isEmpty())
|
||||
return string;
|
||||
@@ -70,17 +106,19 @@ QString StringTable::insert(const QString &string)
|
||||
|
||||
void StringTable::scheduleGC()
|
||||
{
|
||||
QMetaObject::invokeMethod(&m_gcCountDown, "start", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(&m_instance->m_gcCountDown, "start", Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void StringTable::startGC()
|
||||
void StringTable::initialize()
|
||||
{
|
||||
QThreadPool::globalInstance()->start(&m_gcRunner);
|
||||
m_instance = new StringTablePrivate;
|
||||
}
|
||||
|
||||
enum {
|
||||
DebugStringTable = 0
|
||||
};
|
||||
void StringTable::destroy()
|
||||
{
|
||||
delete m_instance;
|
||||
m_instance = nullptr;
|
||||
}
|
||||
|
||||
static inline bool isQStringInUse(const QString &string)
|
||||
{
|
||||
@@ -88,7 +126,7 @@ static inline bool isQStringInUse(const QString &string)
|
||||
return data_ptr->ref.isShared() || data_ptr->ref.isStatic();
|
||||
}
|
||||
|
||||
void StringTable::GC()
|
||||
void StringTablePrivate::GC()
|
||||
{
|
||||
QMutexLocker locker(&m_lock);
|
||||
|
||||
|
@@ -25,45 +25,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QAtomicInt>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QRunnable>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
#include <QString>
|
||||
|
||||
namespace CppTools {
|
||||
namespace Internal {
|
||||
|
||||
class StringTable: public QObject
|
||||
class CppToolsPluginPrivate;
|
||||
|
||||
class StringTable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
StringTable();
|
||||
|
||||
QString insert(const QString &string);
|
||||
void scheduleGC();
|
||||
static QString insert(const QString &string);
|
||||
static void scheduleGC();
|
||||
|
||||
private:
|
||||
void startGC();
|
||||
void GC();
|
||||
|
||||
class GCRunner: public QRunnable {
|
||||
StringTable &m_stringTable;
|
||||
|
||||
public:
|
||||
GCRunner(StringTable &stringTable): m_stringTable(stringTable) {}
|
||||
virtual void run() { m_stringTable.GC(); }
|
||||
} m_gcRunner;
|
||||
friend class GCRunner;
|
||||
|
||||
private:
|
||||
mutable QMutex m_lock;
|
||||
QAtomicInt m_stopGCRequested;
|
||||
QSet<QString> m_strings;
|
||||
QTimer m_gcCountDown;
|
||||
friend class CppToolsPluginPrivate;
|
||||
static void initialize();
|
||||
static void destroy();
|
||||
};
|
||||
|
||||
} // Internal namespace
|
||||
} // CppTools namespace
|
||||
} // Internal
|
||||
} // CppTools
|
||||
|
Reference in New Issue
Block a user