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
|
||||
QSet<FilePath> m_changedFiles; // watched file paths collected from file watcher notifications
|
||||
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
|
||||
|
||||
QList<DocumentManager::RecentFile> m_recentFiles;
|
||||
@@ -367,9 +367,10 @@ void DocumentManager::addDocuments(const QList<IDocument *> &documents, bool add
|
||||
static void removeFileInfo(IDocument *document)
|
||||
{
|
||||
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;
|
||||
const FilePaths filePaths = d->m_documentsWithWatch.value(document);
|
||||
const FilePaths filePaths = *it;
|
||||
for (const FilePath &filePath : filePaths) {
|
||||
if (!d->m_states.contains(filePath))
|
||||
continue;
|
||||
@@ -393,7 +394,7 @@ static void removeFileInfo(IDocument *document)
|
||||
d->m_states.remove(filePath);
|
||||
}
|
||||
}
|
||||
d->m_documentsWithWatch.remove(document);
|
||||
d->m_documentsWithWatch.erase(it);
|
||||
}
|
||||
|
||||
/// 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
|
||||
QList<IDocument *> documentsToRename;
|
||||
for (auto it = d->m_documentsWithWatch.cbegin(), end = d->m_documentsWithWatch.cend();
|
||||
it != end; ++it) {
|
||||
if (it.value().contains(fromKey))
|
||||
for (auto it = d->m_documentsWithWatch.cbegin(); it != d->m_documentsWithWatch.cend(); ++it) {
|
||||
if (it->contains(fromKey))
|
||||
documentsToRename.append(it.key());
|
||||
}
|
||||
|
||||
@@ -544,9 +544,8 @@ QList<IDocument *> DocumentManager::modifiedDocuments()
|
||||
{
|
||||
QList<IDocument *> modified;
|
||||
|
||||
const auto docEnd = d->m_documentsWithWatch.keyEnd();
|
||||
for (auto docIt = d->m_documentsWithWatch.keyBegin(); docIt != docEnd; ++docIt) {
|
||||
IDocument *document = *docIt;
|
||||
for (auto it = d->m_documentsWithWatch.cbegin(); it != d->m_documentsWithWatch.cend(); ++it) {
|
||||
IDocument *document = it.key();
|
||||
if (document->isModified())
|
||||
modified << document;
|
||||
}
|
||||
|
Reference in New Issue
Block a user