mirror of
https://github.com/znc/znc.git
synced 2026-08-06 17:03:14 +02:00
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:
@@ -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() {
|
||||
|
||||
@@ -240,6 +240,7 @@ protected:
|
||||
bool m_bAppendTimestamp;
|
||||
bool m_bPrependTimestamp;
|
||||
bool m_bIRCConnectEnabled;
|
||||
CIRCSock* m_pIRCSock;
|
||||
|
||||
CKeepNickTimer* m_pKeepNickTimer;
|
||||
CJoinTimer* m_pJoinTimer;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user