From a77de4ea65a65055db5f216b6a5ec0ad1c571b29 Mon Sep 17 00:00:00 2001 From: psychon Date: Tue, 13 May 2008 18:18:51 +0000 Subject: [PATCH] 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 --- User.cpp | 11 +++++++---- User.h | 1 + znc.cpp | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/User.cpp b/User.cpp index 1f596da6..af82876c 100644 --- a/User.cpp +++ b/User.cpp @@ -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() { diff --git a/User.h b/User.h index 2803d170..3dbad504 100644 --- a/User.h +++ b/User.h @@ -240,6 +240,7 @@ protected: bool m_bAppendTimestamp; bool m_bPrependTimestamp; bool m_bIRCConnectEnabled; + CIRCSock* m_pIRCSock; CKeepNickTimer* m_pKeepNickTimer; CJoinTimer* m_pJoinTimer; diff --git a/znc.cpp b/znc.cpp index e9066c87..4b9359f6 100644 --- a/znc.cpp +++ b/znc.cpp @@ -100,6 +100,8 @@ bool CZNC::OnBoot() { bool CZNC::ConnectUser(CUser *pUser) { CString sSockName = "IRC::" + pUser->GetUserName(); + // Don't use pUser->GetIRCSock(), as that only returns something if the + // CIRCSock is already connected, not when it's still connecting! CIRCSock* pIRCSock = (CIRCSock*) m_Manager.FindSockByName(sSockName); if (m_pISpoofLockFile != NULL) {