mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 08:43:08 -07:00
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:
parent
4ed8b31641
commit
c6f3da1097
7 changed files with 60 additions and 31 deletions
|
@ -44,6 +44,7 @@
|
|||
#include <QRegExp>
|
||||
#include <QUrl>
|
||||
|
||||
#include "base/algorithm.h"
|
||||
#include "base/global.h"
|
||||
#include "base/http/httperror.h"
|
||||
#include "base/iconprovider.h"
|
||||
|
@ -527,11 +528,14 @@ void WebApplication::sessionStart()
|
|||
|
||||
// remove outdated sessions
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch() / 1000;
|
||||
const QHash<QString, WebSession *> sessionsCopy {m_sessions};
|
||||
for (const auto session : sessionsCopy) {
|
||||
if ((now - session->timestamp()) > INACTIVE_TIME)
|
||||
delete m_sessions.take(session->id());
|
||||
}
|
||||
Algorithm::removeIf(m_sessions, [now](const QString &, const WebSession *session)
|
||||
{
|
||||
if ((now - session->timestamp()) <= INACTIVE_TIME)
|
||||
return false;
|
||||
|
||||
delete session;
|
||||
return true;
|
||||
});
|
||||
|
||||
m_currentSession = new WebSession(generateSid());
|
||||
m_sessions[m_currentSession->id()] = m_currentSession;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue