Skip to content

Commit fbdbd57

Browse files
authored
Merge pull request #76 - KDChartModelDataCache::modelReset: simplify code
KDChartModelDataCache::modelReset: call rowCount & columnCount only once
2 parents d81fafa + c0035ad commit fbdbd57

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/KDChart/KDChartModelDataCache_p.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,13 @@ class ModelDataCache : public ModelDataCachePrivate::ModelSignalMapper
277277
if (m_model == nullptr)
278278
return;
279279

280-
m_data.fill(QVector<T>(m_model->columnCount(m_rootIndex)), m_model->rowCount(m_rootIndex));
281-
m_cacheValid.fill(QVector<bool>(m_model->columnCount(m_rootIndex), false), m_model->rowCount(m_rootIndex));
280+
const int columnCount = m_model->columnCount(m_rootIndex);
281+
const int rowCount = m_model->rowCount(m_rootIndex);
282+
m_data.fill(QVector<T>(columnCount), rowCount);
283+
m_cacheValid.fill(QVector<bool>(columnCount, false), rowCount);
282284

283-
Q_ASSERT(m_data.count() == m_model->rowCount(m_rootIndex));
284-
Q_ASSERT(m_cacheValid.count() == m_model->rowCount(m_rootIndex));
285+
Q_ASSERT(m_data.count() == rowCount);
286+
Q_ASSERT(m_cacheValid.count() == rowCount);
285287
}
286288

287289
void rowsInserted(const QModelIndex &parent, int start, int end) override
@@ -295,8 +297,9 @@ class ModelDataCache : public ModelDataCachePrivate::ModelSignalMapper
295297
Q_ASSERT(start <= end);
296298
Q_ASSERT(end - start + 1 <= m_model->rowCount(m_rootIndex));
297299

298-
m_data.insert(start, end - start + 1, QVector<T>(m_model->columnCount(m_rootIndex)));
299-
m_cacheValid.insert(start, end - start + 1, QVector<bool>(m_model->columnCount(m_rootIndex), false));
300+
const int columnCount = m_model->columnCount(m_rootIndex);
301+
m_data.insert(start, end - start + 1, QVector<T>(columnCount));
302+
m_cacheValid.insert(start, end - start + 1, QVector<bool>(columnCount, false));
300303

301304
Q_ASSERT(m_data.count() == m_model->rowCount(m_rootIndex));
302305
Q_ASSERT(m_cacheValid.count() == m_model->rowCount(m_rootIndex));

0 commit comments

Comments
 (0)