Optimize SortFilterModel role names
* Reserve m_roleIds * Avoid double lookup contains+value but use default value argument * Constify Differential Revision: https://phabricator.kde.org/D8639
This commit is contained in:
parent
d51456bdfc
commit
3ebdd64e6b
@ -53,6 +53,7 @@ void SortFilterModel::syncRoleNames()
|
||||
|
||||
m_roleIds.clear();
|
||||
const QHash<int, QByteArray> rNames = roleNames();
|
||||
m_roleIds.reserve(rNames.count());
|
||||
for (auto i = rNames.constBegin(); i != rNames.constEnd(); ++i) {
|
||||
m_roleIds[i.value()] = i.key();
|
||||
}
|
||||
@ -62,12 +63,9 @@ void SortFilterModel::syncRoleNames()
|
||||
setSortRole(m_sortRole);
|
||||
}
|
||||
|
||||
int SortFilterModel::roleNameToId(const QString &name)
|
||||
int SortFilterModel::roleNameToId(const QString &name) const
|
||||
{
|
||||
if (!m_roleIds.contains(name)) {
|
||||
return Qt::DisplayRole;
|
||||
}
|
||||
return m_roleIds.value(name);
|
||||
return m_roleIds.value(name, Qt::DisplayRole);
|
||||
}
|
||||
|
||||
void SortFilterModel::setModel(QAbstractItemModel *model)
|
||||
|
@ -138,7 +138,7 @@ Q_SIGNALS:
|
||||
Q_REVISION(1) void filterCallbackChanged(const QJSValue &);
|
||||
|
||||
protected:
|
||||
int roleNameToId(const QString &name); //FIXME TODO KF6: This should have been const.
|
||||
int roleNameToId(const QString &name) const;
|
||||
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const Q_DECL_OVERRIDE;
|
||||
|
||||
protected Q_SLOTS:
|
||||
|
Loading…
Reference in New Issue
Block a user