forked from qt-creator/qt-creator
CppTools: Do not call GC() more than necessary
Currently GC() is invoked if
- 5 CppEditors were closed or the last CppEditor was closed
- a project is about to be removed
- a session is about to be unloaded
Thus, for the following use cases, too much GC() calls (can) happen:
- File > Close All
- Close All Projects and Editors
- Changing the session
Fixed by introducing a timer.
Change-Id: I9c984d9de735fc8c6ee77a518e9fb5b63dba5881
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -233,6 +233,10 @@ CppModelManager::CppModelManager(QObject *parent)
|
||||
ProjectExplorer::ProjectExplorerPlugin *pe = ProjectExplorer::ProjectExplorerPlugin::instance();
|
||||
QTC_ASSERT(pe, return);
|
||||
|
||||
m_delayedGcTimer = new QTimer(this);
|
||||
m_delayedGcTimer->setSingleShot(true);
|
||||
connect(m_delayedGcTimer, SIGNAL(timeout()), this, SLOT(GC()));
|
||||
|
||||
ProjectExplorer::SessionManager *session = pe->session();
|
||||
connect(session, SIGNAL(projectAdded(ProjectExplorer::Project*)),
|
||||
this, SLOT(onProjectAdded(ProjectExplorer::Project*)));
|
||||
@@ -240,6 +244,9 @@ CppModelManager::CppModelManager(QObject *parent)
|
||||
connect(session, SIGNAL(aboutToRemoveProject(ProjectExplorer::Project*)),
|
||||
this, SLOT(onAboutToRemoveProject(ProjectExplorer::Project*)));
|
||||
|
||||
connect(session, SIGNAL(aboutToLoadSession(QString)),
|
||||
this, SLOT(onAboutToLoadSession()));
|
||||
|
||||
connect(session, SIGNAL(aboutToUnloadSession(QString)),
|
||||
this, SLOT(onAboutToUnloadSession()));
|
||||
|
||||
@@ -481,7 +488,7 @@ void CppModelManager::deleteCppEditorSupport(TextEditor::BaseTextEditor *textEdi
|
||||
++numberOfClosedEditors;
|
||||
if (numberOfOpenEditors == 0 || numberOfClosedEditors == 5) {
|
||||
numberOfClosedEditors = 0;
|
||||
GC();
|
||||
delayedGC();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,6 +670,11 @@ void CppModelManager::onProjectAdded(ProjectExplorer::Project *)
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
void CppModelManager::delayedGC()
|
||||
{
|
||||
m_delayedGcTimer->start(500);
|
||||
}
|
||||
|
||||
void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
||||
{
|
||||
do {
|
||||
@@ -671,6 +683,13 @@ void CppModelManager::onAboutToRemoveProject(ProjectExplorer::Project *project)
|
||||
m_projectToProjectsInfo.remove(project);
|
||||
} while (0);
|
||||
|
||||
delayedGC();
|
||||
}
|
||||
|
||||
void CppModelManager::onAboutToLoadSession()
|
||||
{
|
||||
if (m_delayedGcTimer->isActive())
|
||||
m_delayedGcTimer->stop();
|
||||
GC();
|
||||
}
|
||||
|
||||
@@ -683,8 +702,6 @@ void CppModelManager::onAboutToUnloadSession()
|
||||
m_projectToProjectsInfo.clear();
|
||||
m_dirty = true;
|
||||
} while (0);
|
||||
|
||||
GC();
|
||||
}
|
||||
|
||||
void CppModelManager::onCoreAboutToClose()
|
||||
@@ -729,6 +746,7 @@ void CppModelManager::GC()
|
||||
// Announce removing files and replace the snapshot
|
||||
emit aboutToRemoveFiles(notReachableFiles);
|
||||
replaceSnapshot(newSnapshot);
|
||||
emit gcFinished();
|
||||
}
|
||||
|
||||
void CppModelManager::finishedRefreshingSourceFiles(const QStringList &files)
|
||||
|
||||
Reference in New Issue
Block a user