summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2010-03-11 13:46:56 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2010-03-11 16:21:16 (GMT)
commit4ae11be00b7aa2257d15140373f24ab1c28c0af7 (patch)
treec6ce9ad1a69dfe3e6cdfe88da3ce1b382dcac495 /src
parentdfa979eea762ec94fb3f7b8eb6562756272b6c18 (diff)
downloadQt-4ae11be00b7aa2257d15140373f24ab1c28c0af7.zip
Qt-4ae11be00b7aa2257d15140373f24ab1c28c0af7.tar.gz
Qt-4ae11be00b7aa2257d15140373f24ab1c28c0af7.tar.bz2
Optimize QSortFilterProxyModel
- use QHash instead of QMap - use QVector::reserve when the size is known Reviewed-by: Gabriel
Diffstat (limited to 'src')
-rw-r--r--src/gui/itemviews/qsortfilterproxymodel.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/gui/itemviews/qsortfilterproxymodel.cpp b/src/gui/itemviews/qsortfilterproxymodel.cpp
index c63a07b..5c7d24b7 100644
--- a/src/gui/itemviews/qsortfilterproxymodel.cpp
+++ b/src/gui/itemviews/qsortfilterproxymodel.cpp
@@ -122,10 +122,10 @@ public:
QVector<int> proxy_rows;
QVector<int> proxy_columns;
QVector<QModelIndex> mapped_children;
- QMap<QModelIndex, Mapping *>::const_iterator map_iter;
+ QHash<QModelIndex, Mapping *>::const_iterator map_iter;
};
- mutable QMap<QModelIndex, Mapping*> source_index_mapping;
+ mutable QHash<QModelIndex, Mapping*> source_index_mapping;
int source_sort_column;
int proxy_sort_column;
@@ -142,7 +142,7 @@ public:
QModelIndexPairList saved_persistent_indexes;
- QMap<QModelIndex, Mapping *>::const_iterator create_mapping(
+ QHash<QModelIndex, Mapping *>::const_iterator create_mapping(
const QModelIndex &source_parent) const;
QModelIndex proxy_to_source(const QModelIndex &proxyIndex) const;
QModelIndex source_to_proxy(const QModelIndex &sourceIndex) const;
@@ -150,14 +150,14 @@ public:
void remove_from_mapping(const QModelIndex &source_parent);
- inline QMap<QModelIndex, Mapping *>::const_iterator index_to_iterator(
+ inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator(
const QModelIndex &proxy_index) const
{
Q_ASSERT(proxy_index.isValid());
Q_ASSERT(proxy_index.model() == q_func());
const void *p = proxy_index.internalPointer();
Q_ASSERT(p);
- QMap<QModelIndex, Mapping *>::const_iterator it =
+ QHash<QModelIndex, Mapping *>::const_iterator it =
static_cast<const Mapping*>(p)->map_iter;
Q_ASSERT(it != source_index_mapping.constEnd());
Q_ASSERT(it.value());
@@ -165,7 +165,7 @@ public:
}
inline QModelIndex create_index(int row, int column,
- QMap<QModelIndex, Mapping*>::const_iterator it) const
+ QHash<QModelIndex, Mapping*>::const_iterator it) const
{
return q_func()->createIndex(row, column, *it);
}
@@ -246,7 +246,7 @@ public:
virtual void _q_sourceModelDestroyed();
};
-typedef QMap<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
+typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap;
void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed()
{
@@ -292,11 +292,13 @@ IndexMap::const_iterator QSortFilterProxyModelPrivate::create_mapping(
Mapping *m = new Mapping;
int source_rows = model->rowCount(source_parent);
+ m->source_rows.reserve(source_rows);
for (int i = 0; i < source_rows; ++i) {
if (q->filterAcceptsRow(i, source_parent))
m->source_rows.append(i);
}
int source_cols = model->columnCount(source_parent);
+ m->source_columns.reserve(source_cols);
for (int i = 0; i < source_cols; ++i) {
if (q->filterAcceptsColumn(i, source_parent))
m->source_columns.append(i);