removed unused map lookups

This commit is contained in:
sehraf 2016-02-22 21:09:10 +01:00
parent 77166cbf13
commit dbdfdcd008

View File

@ -2790,10 +2790,14 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
{ {
pgpID = it->second.gpg_id; pgpID = it->second.gpg_id;
// store some references to speed up accessing
RsPeerId &idRef = mostRecentLocation[pgpID];
bool &recentRef = hasRecentLocation[pgpID];
if (now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE) if (now > it->second.lastcontact + RS_PEER_OFFLINE_DELETE)
{ {
// location is too old // location is too old
if(hasRecentLocation[pgpID]) if(recentRef)
{ {
// there is already one location that won't get removed // there is already one location that won't get removed
// -> we can safely remove this one // -> we can safely remove this one
@ -2805,7 +2809,9 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
else else
{ {
// we need to take care that the most recent location it not removed // we need to take care that the most recent location it not removed
if(mostRecentTime[pgpID] > it->second.lastcontact) time_t &timeRef = mostRecentTime[pgpID];
if(timeRef > it->second.lastcontact)
{ {
// this (it) location is longer offline compared to mostRecentLocation // this (it) location is longer offline compared to mostRecentLocation
// -> we can remove this one // -> we can remove this one
@ -2818,28 +2824,28 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
{ {
// this (it) location is more recent compared to mostRecentLocation // this (it) location is more recent compared to mostRecentLocation
// -> we can remove mostRecentLocation // -> we can remove mostRecentLocation
if(!mostRecentLocation[pgpID].isNull()) if(!idRef.isNull())
{ {
toRemove.push_back(mostRecentLocation[pgpID]); toRemove.push_back(idRef);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl;
#endif #endif
} }
// update maps // update maps
mostRecentLocation[pgpID] = it->first; idRef = it->first;
mostRecentTime[pgpID] = it->second.lastcontact; timeRef = it->second.lastcontact;
} }
} }
} }
else else
{ {
// found a location that won't get removed // found a location that won't get removed
hasRecentLocation[pgpID] = true; recentRef = true;
// we can remove mostRecentLocation if it is set // we can remove mostRecentLocation if it is set
if(!mostRecentLocation[pgpID].isNull()) if(!idRef.isNull())
{ {
toRemove.push_back(mostRecentLocation[pgpID]); toRemove.push_back(idRef);
#ifdef PEER_DEBUG #ifdef PEER_DEBUG
std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl; std::cerr << "p3PeerMgr::removeUnusedLocations() removing Old SSL Id: " << it->first << std::endl;
#endif #endif
@ -2858,8 +2864,8 @@ bool p3PeerMgrIMPL::removeUnusedLocations()
} }
} }
std::list<RsPeerId>::iterator it;
std::list<RsPeerId>::iterator it;
for(it = toRemove.begin(); it != toRemove.end(); ++it) for(it = toRemove.begin(); it != toRemove.end(); ++it)
{ {
removeFriend(*it, false); removeFriend(*it, false);