From fa9deea6716564e9e463b740936129b174690948 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 23 Feb 2015 10:15:53 +0200 Subject: [PATCH] Core: Minor optimizations in DocumentModel Required for followup changes Change-Id: I6280427433bd88fedf87e4d8d25c2f7481d94210 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/editormanager/documentmodel.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/documentmodel.cpp b/src/plugins/coreplugin/editormanager/documentmodel.cpp index e4c51f5838e..38f9de1f14f 100644 --- a/src/plugins/coreplugin/editormanager/documentmodel.cpp +++ b/src/plugins/coreplugin/editormanager/documentmodel.cpp @@ -190,8 +190,10 @@ DocumentModel::Entry *DocumentModel::firstRestoredEntry() void DocumentModelPrivate::addEntry(DocumentModel::Entry *entry) { + const Utils::FileName fileName = entry->fileName(); + // replace a non-loaded entry (aka 'restored') if possible - int previousIndex = indexOfFilePath(entry->fileName()); + int previousIndex = indexOfFilePath(fileName); if (previousIndex >= 0) { if (entry->document && m_entries.at(previousIndex)->document == 0) { DocumentModel::Entry *previousEntry = m_entries.at(previousIndex); @@ -265,13 +267,13 @@ void DocumentModelPrivate::removeDocument(int idx) if (idx < 0) return; QTC_ASSERT(idx < d->m_entries.size(), return); - IDocument *document = d->m_entries.at(idx)->document; int row = idx + 1/**/; beginRemoveRows(QModelIndex(), row, row); - delete d->m_entries.takeAt(idx); + DocumentModel::Entry *entry = d->m_entries.takeAt(idx); endRemoveRows(); - if (document) + if (IDocument *document = entry->document) disconnect(document, SIGNAL(changed()), this, SLOT(itemChanged())); + delete entry; } void DocumentModel::removeAllRestoredEntries()