CUser: Save CIRCSock* instead of looking it up every time

Via profiling ZNC it was found that much CPU time was spent inside FindSockByName()
which in turn was called by CUser::GetIRCSock():

w00t volunteered to write a patch to save that pointer inside CUser and
here is the result. Thanks.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1053 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2008-05-13 18:18:51 +00:00
parent 5ddf977b16
commit a77de4ea65
3 changed files with 10 additions and 4 deletions
+7 -4
View File
@@ -15,6 +15,7 @@
#include "znc.h"
CUser::CUser(const CString& sUserName) {
m_pIRCSock = NULL;
m_fTimezoneOffset = 0;
m_uConnectTime = 0;
SetUserName(sUserName);
@@ -105,6 +106,8 @@ void CUser::DelServers()
}
void CUser::IRCConnected(CIRCSock* pIRCSock) {
m_pIRCSock = pIRCSock;
for (unsigned int a = 0; a < m_vClients.size(); a++) {
m_vClients[a]->IRCConnected(pIRCSock);
}
@@ -113,6 +116,8 @@ void CUser::IRCConnected(CIRCSock* pIRCSock) {
void CUser::IRCDisconnected() {
m_bIRCConnected = false;
m_pIRCSock = NULL;
for (unsigned int a = 0; a < m_vClients.size(); a++) {
m_vClients[a]->IRCDisconnected();
}
@@ -802,13 +807,11 @@ bool CUser::CheckPass(const CString& sPass) {
}*/
CIRCSock* CUser::GetIRCSock() {
// Todo: optimize this by saving a pointer to the sock
return (CIRCSock*) CZNC::Get().GetManager().FindSockByName("IRC::" + m_sUserName);
return m_pIRCSock;
}
const CIRCSock* CUser::GetIRCSock() const {
// Todo: same as above
return (CIRCSock*) CZNC::Get().GetManager().FindSockByName("IRC::" + m_sUserName);
return m_pIRCSock;
}
CString CUser::GetLocalIP() {