diff options
author | Rolf Eike Beer <eike@sf-mail.de> | 2019-03-22 21:25:59 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-03-27 07:36:33 -0700 |
commit | bf9a526d63854f1ebb5bf102d54cc170f29ce370 (patch) | |
tree | cf5c1c06d8ef4f3f6d016f6186be16d2187522b3 /core/connectionlistmodel.cpp | |
parent | 5ad52db451102151b58b0e9b2af1adb80d16105d (diff) | |
download | subsurface-bf9a526d63854f1ebb5bf102d54cc170f29ce370.tar.gz |
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>
Diffstat (limited to 'core/connectionlistmodel.cpp')
-rw-r--r-- | core/connectionlistmodel.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/core/connectionlistmodel.cpp b/core/connectionlistmodel.cpp index 8cd270347..0e4d69828 100644 --- a/core/connectionlistmodel.cpp +++ b/core/connectionlistmodel.cpp @@ -21,7 +21,7 @@ int ConnectionListModel::rowCount(const QModelIndex&) const return m_addresses.count(); } -void ConnectionListModel::addAddress(const QString address) +void ConnectionListModel::addAddress(const QString &address) { if (!m_addresses.contains(address)) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); @@ -37,8 +37,10 @@ void ConnectionListModel::removeAllAddresses() endRemoveRows(); } -int ConnectionListModel::indexOf(QString address) +int ConnectionListModel::indexOf(const QString &address) const { - const QRegExp re(".*" + address + ".*", Qt::CaseInsensitive); - return m_addresses.indexOf(re); + for (int i = 0; i < m_addresses.count(); i++) + if (m_addresses.at(i).contains(address, Qt::CaseInsensitive)) + return i; + return -1; } |