mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
slightly optimize ConnectionListModel
-avoid object copies -use some more bullet proof C++11 constructs -avoid using a QRegExp, simple string matches are faster Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
This commit is contained in:
parent
5ad52db451
commit
bf9a526d63
2 changed files with 11 additions and 9 deletions
|
@ -21,7 +21,7 @@ int ConnectionListModel::rowCount(const QModelIndex&) const
|
||||||
return m_addresses.count();
|
return m_addresses.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionListModel::addAddress(const QString address)
|
void ConnectionListModel::addAddress(const QString &address)
|
||||||
{
|
{
|
||||||
if (!m_addresses.contains(address)) {
|
if (!m_addresses.contains(address)) {
|
||||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||||
|
@ -37,8 +37,10 @@ void ConnectionListModel::removeAllAddresses()
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConnectionListModel::indexOf(QString address)
|
int ConnectionListModel::indexOf(const QString &address) const
|
||||||
{
|
{
|
||||||
const QRegExp re(".*" + address + ".*", Qt::CaseInsensitive);
|
for (int i = 0; i < m_addresses.count(); i++)
|
||||||
return m_addresses.indexOf(re);
|
if (m_addresses.at(i).contains(address, Qt::CaseInsensitive))
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
class ConnectionListModel : public QAbstractListModel {
|
class ConnectionListModel : public QAbstractListModel {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ConnectionListModel(QObject *parent = 0);
|
ConnectionListModel(QObject *parent = nullptr);
|
||||||
QVariant data(const QModelIndex &index, int role) const;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
void addAddress(const QString address);
|
void addAddress(const QString &address);
|
||||||
void removeAllAddresses();
|
void removeAllAddresses();
|
||||||
int indexOf(QString address);
|
int indexOf(const QString &address) const;
|
||||||
private:
|
private:
|
||||||
QStringList m_addresses;
|
QStringList m_addresses;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue