From 21154b10c49ebef4faecedbe3a0fb8a6e9fd56b1 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Mon, 7 May 2012 03:03:14 +0200 Subject: [PATCH] Some speed-optimizations for the Progress model. --- src/Config.h | 2 +- src/Model_Progress.cpp | 40 ++++++++++++++++++++++++++-------------- src/Model_Progress.h | 14 +++++++++----- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/Config.h b/src/Config.h index 11886979..26b679c2 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 5 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 1 -#define VER_LAMEXP_BUILD 1016 +#define VER_LAMEXP_BUILD 1017 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Model_Progress.cpp b/src/Model_Progress.cpp index 6fb28c2b..e6af8ef6 100644 --- a/src/Model_Progress.cpp +++ b/src/Model_Progress.cpp @@ -136,7 +136,7 @@ QVariant ProgressModel::headerData(int section, Qt::Orientation orientation, int void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QString &jobInitialStatus, int jobInitialState) { - if(m_jobList.contains(jobId) || m_jobListHidden.contains(jobId)) + if(m_jobIdentifiers.contains(jobId)) { return; } @@ -145,6 +145,7 @@ void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QSt { beginRemoveRows(QModelIndex(), 0, 0); m_jobListHidden.append(m_jobList.takeFirst()); + m_jobIndexCache.clear(); endRemoveRows(); } @@ -156,33 +157,41 @@ void ProgressModel::addJob(const QUuid &jobId, const QString &jobName, const QSt m_jobStatus.insert(jobId, jobInitialStatus); m_jobState.insert(jobId, jobInitialState); m_jobLogFile.insert(jobId, QStringList()); + m_jobIdentifiers.insert(jobId); endInsertRows(); } void ProgressModel::updateJob(const QUuid &jobId, const QString &newStatus, int newState) { - int row = m_jobList.indexOf(jobId); - - if(row < 0) + if(!m_jobIdentifiers.contains(jobId)) { - if(m_jobListHidden.indexOf(jobId) >= 0) - { - if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus); - if(newState >= 0) m_jobState.insert(jobId, newState); - } return; } - + if(!newStatus.isEmpty()) m_jobStatus.insert(jobId, newStatus); if(newState >= 0) m_jobState.insert(jobId, newState); - - emit dataChanged(index(row, 0), index(row, 1)); + + const int row = m_jobIndexCache.value(jobId, -1); + + if(row >= 0) + { + emit dataChanged(index(row, 0), index(row, 1)); + } + else + { + const int tmp = m_jobList.indexOf(jobId); + if(tmp >= 0) + { + m_jobIndexCache.insert(jobId, tmp); + emit dataChanged(index(tmp, 0), index(tmp, 1)); + } + } } void ProgressModel::appendToLog(const QUuid &jobId, const QString &line) { - if(m_jobList.contains(jobId)) + if(m_jobIdentifiers.contains(jobId)) { m_jobLogFile[jobId].append(line.split('\n')); } @@ -213,7 +222,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type) { const QUuid &jobId = QUuid::createUuid(); - if(m_jobList.contains(jobId)) + if(m_jobIdentifiers.contains(jobId)) { return; } @@ -222,6 +231,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type) { beginRemoveRows(QModelIndex(), 0, 0); m_jobListHidden.append(m_jobList.takeFirst()); + m_jobIndexCache.clear(); endRemoveRows(); } @@ -248,6 +258,7 @@ void ProgressModel::addSystemMessage(const QString &text, int type) m_jobStatus.insert(jobId, QString()); m_jobState.insert(jobId, jobState); m_jobLogFile.insert(jobId, QStringList()); + m_jobIdentifiers.insert(jobId); endInsertRows(); } @@ -261,6 +272,7 @@ void ProgressModel::restoreHiddenItems(void) { m_jobList.prepend(m_jobListHidden.takeLast()); } + m_jobIndexCache.clear(); endResetModel(); } } diff --git a/src/Model_Progress.h b/src/Model_Progress.h index d61d7719..759c8c8d 100644 --- a/src/Model_Progress.h +++ b/src/Model_Progress.h @@ -25,7 +25,9 @@ #include #include -#include +#include +#include +#include #include #include @@ -75,10 +77,12 @@ public slots: private: QList m_jobList; QList m_jobListHidden; - QMap m_jobName; - QMap m_jobStatus; - QMap m_jobState; - QMap m_jobLogFile; + QHash m_jobName; + QHash m_jobStatus; + QHash m_jobState; + QHash m_jobLogFile; + QHash m_jobIndexCache; + QSet m_jobIdentifiers; const QIcon m_iconRunning; const QIcon m_iconPaused;