forked from qt-creator/qt-creator
DocumentModel: Improve performance of (document|entry)ForFilePath
Don't iterate the list, but look up in the hash. Implicitly improves performance of text mark creation. Change-Id: Ic1f7e118b96f81bb5922a94039d3d85027a118a5 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -617,10 +617,10 @@ DocumentModel::Entry *DocumentModel::entryForDocument(IDocument *document)
|
|||||||
|
|
||||||
DocumentModel::Entry *DocumentModel::entryForFilePath(const Utils::FilePath &filePath)
|
DocumentModel::Entry *DocumentModel::entryForFilePath(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
const Utils::optional<int> index = d->indexOfFilePath(filePath);
|
if (filePath.isEmpty())
|
||||||
if (!index)
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return d->m_entries.at(*index);
|
const FilePath fixedPath = DocumentManager::filePathKey(filePath, DocumentManager::ResolveLinks);
|
||||||
|
return d->m_entryByFixedPath.value(fixedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IDocument *> DocumentModel::openedDocuments()
|
QList<IDocument *> DocumentModel::openedDocuments()
|
||||||
@@ -630,10 +630,8 @@ QList<IDocument *> DocumentModel::openedDocuments()
|
|||||||
|
|
||||||
IDocument *DocumentModel::documentForFilePath(const Utils::FilePath &filePath)
|
IDocument *DocumentModel::documentForFilePath(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
const Utils::optional<int> index = d->indexOfFilePath(filePath);
|
const Entry *entry = entryForFilePath(filePath);
|
||||||
if (!index)
|
return entry ? entry->document : nullptr;
|
||||||
return nullptr;
|
|
||||||
return d->m_entries.at(*index)->document;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<IEditor *> DocumentModel::editorsForFilePath(const Utils::FilePath &filePath)
|
QList<IEditor *> DocumentModel::editorsForFilePath(const Utils::FilePath &filePath)
|
||||||
|
Reference in New Issue
Block a user