Improve removeIf() to support set types

We can now replace QMutable*Iterator by removeIf() which usage is more consistent with other
algorithm functions.
This commit is contained in:
Chocobo1 2019-05-12 13:26:06 +08:00
parent 4ed8b31641
commit c6f3da1097
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
7 changed files with 60 additions and 31 deletions

View file

@ -32,7 +32,6 @@
#include <algorithm>
#include <QMutableListIterator>
#include <QNetworkProxy>
#include <QSslCipher>
#include <QSslConfiguration>
@ -40,6 +39,7 @@
#include <QStringList>
#include <QTimer>
#include "base/algorithm.h"
#include "base/utils/net.h"
#include "connection.h"
@ -119,14 +119,14 @@ void Server::removeConnection(Connection *connection)
void Server::dropTimedOutConnection()
{
QMutableSetIterator<Connection *> i(m_connections);
while (i.hasNext()) {
Connection *connection = i.next();
if (connection->hasExpired(KEEP_ALIVE_DURATION)) {
connection->deleteLater();
i.remove();
}
}
Algorithm::removeIf(m_connections, [](Connection *connection)
{
if (!connection->hasExpired(KEEP_ALIVE_DURATION))
return false;
connection->deleteLater();
return true;
});
}
bool Server::setupHttps(const QByteArray &certificates, const QByteArray &privateKey)