mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Avoid a possibly expensive FindSockByName() for finding IRC socks
While a user is connecting to an IRC server, the CUser instance didn't know about the CIRCSock instance (due to historic reasons). This meant that we needed to use FindSockByName() when we had to check if there is any CIRCSock associated with this user. However, this is a bad idea since FindSockByName() is O(n) on the number of sockets that the socket manager is managing. Instead, we now already set CUser::m_pIRCSock when the CIRCSock is created so that checking for an irc socket becomes O(1). This was inspired by the results of profiling a znc instance with 900 users. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@2171 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -245,13 +245,11 @@ void CClient::UserCommand(CString& sLine) {
|
||||
}
|
||||
m_pUser->SetNextServer(pServer);
|
||||
|
||||
if (!GetIRCSock()) {
|
||||
// If we are already connecting to some server,
|
||||
// we have to abort that attempt
|
||||
Csock *pIRCSock = CZNC::Get().GetManager()
|
||||
.FindSockByName("IRC::" + m_pUser->GetUserName());
|
||||
if (pIRCSock)
|
||||
pIRCSock->Close();
|
||||
// If we are already connecting to some server,
|
||||
// we have to abort that attempt
|
||||
Csock *pIRCSock = GetIRCSock();
|
||||
if (pIRCSock && !pIRCSock->IsConnected()) {
|
||||
pIRCSock->Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,13 +276,6 @@ void CClient::UserCommand(CString& sLine) {
|
||||
if (GetIRCSock()) {
|
||||
CString sQuitMsg = sLine.Token(1, true);
|
||||
GetIRCSock()->Quit(sQuitMsg);
|
||||
} else {
|
||||
Csock* pIRCSock;
|
||||
CString sSockName = "IRC::" + m_pUser->GetUserName();
|
||||
// This is *slow*, we try to avoid doing this
|
||||
pIRCSock = CZNC::Get().GetManager().FindSockByName(sSockName);
|
||||
if (pIRCSock)
|
||||
pIRCSock->Close();
|
||||
}
|
||||
|
||||
m_pUser->SetIRCConnectEnabled(false);
|
||||
|
||||
Reference in New Issue
Block a user