1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-22 00:42:04 +02:00

Performance++, Memory--

This commit is contained in:
Uwe L. Korn 2013-06-26 12:03:11 +02:00 committed by Michael Zanetti
parent 546f54f196
commit 7daebc655a
3 changed files with 10 additions and 8 deletions

View File

@ -28,6 +28,7 @@
#include "sip/SipInfo.h"
#include "sip/SipPlugin.h"
#include "utils/Logger.h"
#include "utils/WeakObjectHash.h"
#include <boost/bind.hpp>
#include <qtconcurrentrun.h>
@ -35,21 +36,21 @@
/* Management of ConnectionManagers */
static QMutex nodeMapMutex;
static QMap< QString, QWeakPointer< ConnectionManager > > connectionManagers;
static QMap< QString, QSharedPointer< ConnectionManager > > activeConnectionManagers;
static Tomahawk::Utils::WeakObjectHash< ConnectionManager > connectionManagers;
static QHash< QString, QSharedPointer< ConnectionManager > > activeConnectionManagers;
QSharedPointer<ConnectionManager>
ConnectionManager::getManagerForNodeId( const QString &nodeid )
{
QMutexLocker locker( &nodeMapMutex );
if ( connectionManagers.contains( nodeid ) && !connectionManagers.value( nodeid ).isNull() ) {
return connectionManagers.value( nodeid ).toStrongRef();
if ( connectionManagers.hash().contains( nodeid ) && !connectionManagers.hash().value( nodeid ).isNull() ) {
return connectionManagers.hash().value( nodeid ).toStrongRef();
}
// There exists no connection for this nodeid
QSharedPointer< ConnectionManager > manager( new ConnectionManager( nodeid ) );
manager->setWeakRef( manager.toWeakRef() );
connectionManagers[nodeid] = manager->weakRef();
connectionManagers.insert( nodeid, manager.toWeakRef() );
return manager;
}

View File

@ -49,7 +49,7 @@ public:
*/
static void setActive( bool active, const QString& nodeid, const QSharedPointer<ConnectionManager>& manager );
~ConnectionManager();
virtual ~ConnectionManager();
/**
* Receive incoming SipInfos and start a new thread to connect to this peer.

View File

@ -492,7 +492,7 @@ Servent::registerPeer( const Tomahawk::peerinfo_ptr& peerInfo )
peerInfoDebug(peerInfo) << "we need to establish the connection now... thinking";
if ( !connectedToSession( peerInfo->nodeId() ) )
{
ConnectionManager::getManagerForNodeId( peerInfo->nodeId() )->handleSipInfo( peerInfo );
handleSipInfo( peerInfo );
}
else
{
@ -556,7 +556,8 @@ Servent::handleSipInfo( const Tomahawk::peerinfo_ptr& peerInfo )
if ( peerInfo->sipInfos().isEmpty() )
return;
ConnectionManager::getManagerForNodeId( peerInfo->nodeId() )->handleSipInfo( peerInfo );
QSharedPointer<ConnectionManager> manager = ConnectionManager::getManagerForNodeId( peerInfo->nodeId() );
manager->handleSipInfo( peerInfo );
}