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