forked from qt-creator/qt-creator
DocumentManager: Replace QMap with QHash
The key is a pointer, so use QHash. Simplify some lookups. Change-Id: I3304d9cd8fd0456877d0f3fb66d2b872d23fa86a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -149,7 +149,7 @@ public:
|
|||||||
QMap<FilePath, FileState> m_states; // filePathKey -> FileState
|
QMap<FilePath, FileState> m_states; // filePathKey -> FileState
|
||||||
QSet<FilePath> m_changedFiles; // watched file paths collected from file watcher notifications
|
QSet<FilePath> m_changedFiles; // watched file paths collected from file watcher notifications
|
||||||
QList<IDocument *> m_documentsWithoutWatch;
|
QList<IDocument *> m_documentsWithoutWatch;
|
||||||
QMap<IDocument *, FilePaths> m_documentsWithWatch; // document -> list of filePathKeys
|
QHash<IDocument *, FilePaths> m_documentsWithWatch; // document -> list of filePathKeys
|
||||||
QSet<FilePath> m_expectedFileNames; // set of file paths without normalization
|
QSet<FilePath> m_expectedFileNames; // set of file paths without normalization
|
||||||
|
|
||||||
QList<DocumentManager::RecentFile> m_recentFiles;
|
QList<DocumentManager::RecentFile> m_recentFiles;
|
||||||
@@ -367,9 +367,10 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add
|
|||||||
static void removeFileInfo(IDocument *document)
|
static void removeFileInfo(IDocument *document)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(isMainThread(), return);
|
QTC_ASSERT(isMainThread(), return);
|
||||||
if (!d->m_documentsWithWatch.contains(document))
|
const auto it = d->m_documentsWithWatch.constFind(document);
|
||||||
|
if (it == d->m_documentsWithWatch.constEnd())
|
||||||
return;
|
return;
|
||||||
const FilePaths filePaths = d->m_documentsWithWatch.value(document);
|
const FilePaths filePaths = *it;
|
||||||
for (const FilePath &filePath : filePaths) {
|
for (const FilePath &filePath : filePaths) {
|
||||||
if (!d->m_states.contains(filePath))
|
if (!d->m_states.contains(filePath))
|
||||||
continue;
|
continue;
|
||||||
@@ -393,7 +394,7 @@ static void removeFileInfo(IDocument *document)
|
|||||||
d->m_states.remove(filePath);
|
d->m_states.remove(filePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d->m_documentsWithWatch.remove(document);
|
d->m_documentsWithWatch.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps the state of the file manager's map
|
/// Dumps the state of the file manager's map
|
||||||
@@ -448,9 +449,8 @@ void DocumentManager::renamedFile(const Utils::FilePath &from, const Utils::File
|
|||||||
|
|
||||||
// gather the list of IDocuments
|
// gather the list of IDocuments
|
||||||
QList<IDocument *> documentsToRename;
|
QList<IDocument *> documentsToRename;
|
||||||
for (auto it = d->m_documentsWithWatch.cbegin(), end = d->m_documentsWithWatch.cend();
|
for (auto it = d->m_documentsWithWatch.cbegin(); it != d->m_documentsWithWatch.cend(); ++it) {
|
||||||
it != end; ++it) {
|
if (it->contains(fromKey))
|
||||||
if (it.value().contains(fromKey))
|
|
||||||
documentsToRename.append(it.key());
|
documentsToRename.append(it.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -544,9 +544,8 @@ QList<IDocument *> DocumentManager::modifiedDocuments()
|
|||||||
{
|
{
|
||||||
QList<IDocument *> modified;
|
QList<IDocument *> modified;
|
||||||
|
|
||||||
const auto docEnd = d->m_documentsWithWatch.keyEnd();
|
for (auto it = d->m_documentsWithWatch.cbegin(); it != d->m_documentsWithWatch.cend(); ++it) {
|
||||||
for (auto docIt = d->m_documentsWithWatch.keyBegin(); docIt != docEnd; ++docIt) {
|
IDocument *document = it.key();
|
||||||
IDocument *document = *docIt;
|
|
||||||
if (document->isModified())
|
if (document->isModified())
|
||||||
modified << document;
|
modified << document;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user