forked from qt-creator/qt-creator
Slight optimization in Session::projectForFile
Avoid creating a copy of the list of projects.
This commit is contained in:
@@ -194,7 +194,7 @@ QString SearchSymbols::symbolName(const Symbol *symbol) const
|
|||||||
void SearchSymbols::appendItem(const QString &name,
|
void SearchSymbols::appendItem(const QString &name,
|
||||||
const QString &info,
|
const QString &info,
|
||||||
ModelItemInfo::ItemType type,
|
ModelItemInfo::ItemType type,
|
||||||
const CPlusPlus::Symbol *symbol)
|
const Symbol *symbol)
|
||||||
{
|
{
|
||||||
const QIcon icon = icons.iconForSymbol(symbol);
|
const QIcon icon = icons.iconForSymbol(symbol);
|
||||||
items.append(ModelItemInfo(name, info, type,
|
items.append(ModelItemInfo(name, info, type,
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ void SessionManager::editDependencies()
|
|||||||
dlg.exec();
|
dlg.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Project *> SessionManager::projects() const
|
const QList<Project *> &SessionManager::projects() const
|
||||||
{
|
{
|
||||||
return m_file->m_projects;
|
return m_file->m_projects;
|
||||||
}
|
}
|
||||||
@@ -839,26 +839,26 @@ Project *SessionManager::projectForFile(const QString &fileName) const
|
|||||||
if (debug)
|
if (debug)
|
||||||
qDebug() << "SessionManager::projectForFile(" << fileName << ")";
|
qDebug() << "SessionManager::projectForFile(" << fileName << ")";
|
||||||
|
|
||||||
Project *project = 0;
|
const QList<Project *> &projectList = projects();
|
||||||
|
|
||||||
QList<Project *> projectList = projects();
|
// Check current project first
|
||||||
|
Project *currentProject = ProjectExplorerPlugin::instance()->currentProject();
|
||||||
|
if (currentProject && projectContainsFile(currentProject, fileName))
|
||||||
|
return currentProject;
|
||||||
|
|
||||||
// Always check current project first
|
foreach (Project *p, projectList)
|
||||||
if (Project *currentProject = ProjectExplorerPlugin::instance()->currentProject()) {
|
if (p != currentProject && projectContainsFile(p, fileName))
|
||||||
projectList.removeOne(currentProject);
|
return p;
|
||||||
projectList.insert(0, currentProject);
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Project *p, projectList) {
|
bool SessionManager::projectContainsFile(Project *p, const QString &fileName) const
|
||||||
if (!m_projectFileCache.contains(p)) {
|
{
|
||||||
|
if (!m_projectFileCache.contains(p))
|
||||||
m_projectFileCache.insert(p, p->files(Project::AllFiles));
|
m_projectFileCache.insert(p, p->files(Project::AllFiles));
|
||||||
}
|
|
||||||
if (m_projectFileCache.value(p).contains(fileName)) {
|
return m_projectFileCache.value(p).contains(fileName);
|
||||||
project = p;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return project;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileName)
|
void SessionManager::setEditorCodec(Core::IEditor *editor, const QString &fileName)
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public:
|
|||||||
Core::IFile *file() const;
|
Core::IFile *file() const;
|
||||||
Project *startupProject() const;
|
Project *startupProject() const;
|
||||||
|
|
||||||
QList<Project *> projects() const;
|
const QList<Project *> &projects() const;
|
||||||
|
|
||||||
bool isDefaultVirgin() const;
|
bool isDefaultVirgin() const;
|
||||||
bool isDefaultSession(const QString &session) const;
|
bool isDefaultSession(const QString &session) const;
|
||||||
@@ -182,6 +182,7 @@ private:
|
|||||||
bool loadImpl(const QString &fileName);
|
bool loadImpl(const QString &fileName);
|
||||||
bool createImpl(const QString &fileName);
|
bool createImpl(const QString &fileName);
|
||||||
QString sessionNameToFileName(const QString &session);
|
QString sessionNameToFileName(const QString &session);
|
||||||
|
bool projectContainsFile(Project *p, const QString &fileName) const;
|
||||||
|
|
||||||
bool recursiveDependencyCheck(const QString &newDep, const QString &checkDep) const;
|
bool recursiveDependencyCheck(const QString &newDep, const QString &checkDep) const;
|
||||||
QStringList dependencies(const QString &proName) const;
|
QStringList dependencies(const QString &proName) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user