mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Make CChan smaller
This is mostly done by removing unused members, but there is also removes a cache which saved how many opped, voiced etc users are on a channel. This shouldn't result in a big slowdown, since this data is only ever used for /msg *status listchans. Also, this replaces the API to access this data with a version which should be faster especially for big channels. On amd64 the size of CChan was 600 bytes before and is 400 bytes now. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1301 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -34,13 +34,8 @@ CChan::~CChan() {
|
||||
}
|
||||
|
||||
void CChan::Reset() {
|
||||
m_bWhoDone = false;
|
||||
m_bIsOn = false;
|
||||
m_suUserPerms.clear();
|
||||
m_musModes.clear();
|
||||
m_muuPermCount.clear();
|
||||
m_uLimit = 0;
|
||||
m_uClientRequests = 0;
|
||||
m_sTopic = "";
|
||||
m_sTopicOwner = "";
|
||||
m_ulTopicDate = 0;
|
||||
@@ -98,8 +93,6 @@ void CChan::Cycle() const {
|
||||
|
||||
void CChan::JoinUser(bool bForce, const CString& sKey, CClient* pClient) {
|
||||
if (!bForce && (!IsOn() || !IsDetached())) {
|
||||
IncClientRequests();
|
||||
|
||||
m_pUser->PutIRC("JOIN " + GetName() + " " + ((sKey.empty()) ? GetKey() : sKey));
|
||||
return;
|
||||
}
|
||||
@@ -203,32 +196,9 @@ CString CChan::GetModeForNames() const {
|
||||
|
||||
void CChan::SetModes(const CString& sModes) {
|
||||
m_musModes.clear();
|
||||
m_uLimit = 0;
|
||||
ModeChange(sModes);
|
||||
}
|
||||
|
||||
void CChan::IncClientRequests() {
|
||||
m_uClientRequests++;
|
||||
}
|
||||
|
||||
bool CChan::DecClientRequests() {
|
||||
if (!m_uClientRequests) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_uClientRequests--;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CChan::Who() {
|
||||
if (m_bWhoDone) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pUser->PutIRC("WHO " + GetName());
|
||||
return true;
|
||||
}
|
||||
|
||||
void CChan::OnWho(const CString& sNick, const CString& sIdent, const CString& sHost) {
|
||||
CNick* pNick = FindNick(sNick);
|
||||
|
||||
@@ -266,17 +236,13 @@ void CChan::ModeChange(const CString& sModes, const CString& sOpNick) {
|
||||
|
||||
if (uPerm) {
|
||||
if (bAdd) {
|
||||
if (pNick->AddPerm(uPerm)) {
|
||||
IncPermCount(uPerm);
|
||||
}
|
||||
pNick->AddPerm(uPerm);
|
||||
|
||||
if (pNick->GetNick().Equals(m_pUser->GetCurNick())) {
|
||||
AddPerm(uPerm);
|
||||
}
|
||||
} else {
|
||||
if (pNick->RemPerm(uPerm)) {
|
||||
DecPermCount(uPerm);
|
||||
}
|
||||
pNick->RemPerm(uPerm);
|
||||
|
||||
if (pNick->GetNick().Equals(m_pUser->GetCurNick())) {
|
||||
RemPerm(uPerm);
|
||||
@@ -462,9 +428,7 @@ bool CChan::AddNick(const CString& sNick) {
|
||||
pNick->SetHost(sHost);
|
||||
|
||||
for (CString::size_type i = 0; i < sPrefix.length(); i++) {
|
||||
if (pNick->AddPerm(sPrefix[i])) {
|
||||
IncPermCount(sPrefix[i]);
|
||||
}
|
||||
pNick->AddPerm(sPrefix[i]);
|
||||
}
|
||||
|
||||
if (pNick->GetNick().Equals(m_pUser->GetCurNick())) {
|
||||
@@ -478,31 +442,19 @@ bool CChan::AddNick(const CString& sNick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int CChan::GetPermCount(unsigned char uPerm) const {
|
||||
map<unsigned char, unsigned int>::const_iterator it = m_muuPermCount.find(uPerm);
|
||||
return (it == m_muuPermCount.end()) ? 0 : it->second;
|
||||
}
|
||||
map<char, unsigned int> CChan::GetPermCounts() const {
|
||||
map<char, unsigned int> mRet;
|
||||
|
||||
void CChan::DecPermCount(unsigned char uPerm) {
|
||||
map<unsigned char, unsigned int>::iterator it = m_muuPermCount.find(uPerm);
|
||||
map<CString,CNick*>::const_iterator it;
|
||||
for (it = m_msNicks.begin(); it != m_msNicks.end(); it++) {
|
||||
CString sPerms = it->second->GetPermStr();
|
||||
|
||||
if (it == m_muuPermCount.end()) {
|
||||
m_muuPermCount[uPerm] = 0;
|
||||
} else {
|
||||
if (it->second) {
|
||||
m_muuPermCount[uPerm]--;
|
||||
for (unsigned int p = 0; p < sPerms.size(); p++) {
|
||||
mRet[sPerms[p]]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CChan::IncPermCount(unsigned char uPerm) {
|
||||
map<unsigned char, unsigned int>::iterator it = m_muuPermCount.find(uPerm);
|
||||
|
||||
if (it == m_muuPermCount.end()) {
|
||||
m_muuPermCount[uPerm] = 1;
|
||||
} else {
|
||||
m_muuPermCount[uPerm]++;
|
||||
}
|
||||
return mRet;
|
||||
}
|
||||
|
||||
bool CChan::RemNick(const CString& sNick) {
|
||||
@@ -514,12 +466,6 @@ bool CChan::RemNick(const CString& sNick) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const set<unsigned char>& suPerms = it->second->GetChanPerms();
|
||||
|
||||
for (it2 = suPerms.begin(); it2 != suPerms.end(); it2++) {
|
||||
DecPermCount(*it2);
|
||||
}
|
||||
|
||||
delete it->second;
|
||||
m_msNicks.erase(it);
|
||||
|
||||
|
||||
@@ -61,10 +61,6 @@ public:
|
||||
void DetachUser();
|
||||
void AttachUser();
|
||||
|
||||
void IncClientRequests();
|
||||
bool DecClientRequests();
|
||||
|
||||
bool Who();
|
||||
void OnWho(const CString& sNick, const CString& sIdent, const CString& sHost);
|
||||
|
||||
// Modes
|
||||
@@ -102,8 +98,6 @@ public:
|
||||
// !wrappers
|
||||
|
||||
// Setters
|
||||
void IncPermCount(unsigned char uPerm);
|
||||
void DecPermCount(unsigned char uPerm);
|
||||
void SetIsOn(bool b) { m_bIsOn = b; if (!b) { Reset(); } }
|
||||
void SetKey(const CString& s) { m_sKey = s; }
|
||||
void SetTopic(const CString& s) { m_sTopic = s; }
|
||||
@@ -112,7 +106,6 @@ public:
|
||||
void SetDefaultModes(const CString& s) { m_sDefaultModes = s; }
|
||||
void SetBufferCount(unsigned int u) { m_uBufferCount = u; }
|
||||
void SetKeepBuffer(bool b) { m_bKeepBuffer = b; }
|
||||
void SetWhoDone(bool b = true) { m_bWhoDone = b; }
|
||||
void SetDetached(bool b = true) { m_bDetached = b; }
|
||||
void SetInConfig(bool b) { m_bInConfig = b; }
|
||||
void SetCreationDate(unsigned long u) { m_ulCreationDate = u; }
|
||||
@@ -126,17 +119,15 @@ public:
|
||||
bool HasMode(unsigned char uMode) const;
|
||||
CString GetOptions() const;
|
||||
CString GetModeArg(unsigned char uMode) const;
|
||||
unsigned int GetPermCount(unsigned char uPerm) const;
|
||||
map<char, unsigned int> GetPermCounts() const;
|
||||
bool IsOn() const { return m_bIsOn; }
|
||||
const CString& GetName() const { return m_sName; }
|
||||
const map<unsigned char, CString>& GetModes() const { return m_musModes; }
|
||||
const CString& GetKey() const { return m_sKey; }
|
||||
unsigned int GetLimit() const { return m_uLimit; }
|
||||
const CString& GetTopic() const { return m_sTopic; }
|
||||
const CString& GetTopicOwner() const { return m_sTopicOwner; }
|
||||
unsigned int GetTopicDate() const { return m_ulTopicDate; }
|
||||
const CString& GetDefaultModes() const { return m_sDefaultModes; }
|
||||
const vector<CString>& GetBans() const { return m_vsBans; }
|
||||
const vector<CString>& GetBuffer() const { return m_vsBuffer; }
|
||||
const map<CString,CNick*>& GetNicks() const { return m_msNicks; }
|
||||
unsigned int GetNickCount() const { return m_msNicks.size(); }
|
||||
@@ -152,7 +143,6 @@ private:
|
||||
protected:
|
||||
bool m_bDetached;
|
||||
bool m_bIsOn;
|
||||
bool m_bWhoDone;
|
||||
bool m_bKeepBuffer;
|
||||
bool m_bInConfig;
|
||||
bool m_bDisabled;
|
||||
@@ -164,18 +154,13 @@ protected:
|
||||
unsigned long m_ulCreationDate;
|
||||
CUser* m_pUser;
|
||||
CNick m_Nick;
|
||||
unsigned int m_uLimit;
|
||||
unsigned int m_uJoinTries;
|
||||
CString m_sDefaultModes;
|
||||
vector<CString> m_vsBans;
|
||||
map<CString,CNick*> m_msNicks; // Todo: make this caseless (irc style)
|
||||
set<unsigned int> m_suUserPerms;
|
||||
unsigned int m_uBufferCount;
|
||||
unsigned int m_uClientRequests; // Used to tell how many times a client tried to join this chan
|
||||
vector<CString> m_vsBuffer;
|
||||
|
||||
map<unsigned char, CString> m_musModes;
|
||||
map<unsigned char, unsigned int> m_muuPermCount;
|
||||
};
|
||||
|
||||
#endif // !_CHAN_H
|
||||
|
||||
+3
-3
@@ -305,10 +305,10 @@ void CClient::UserCommand(const CString& sLine) {
|
||||
Table.SetCell("Modes", pChan->GetModeString());
|
||||
Table.SetCell("Users", CString(pChan->GetNickCount()));
|
||||
|
||||
map<char, unsigned int> mPerms = pChan->GetPermCounts();
|
||||
for (unsigned int b = 0; b < sPerms.size(); b++) {
|
||||
CString sPerm;
|
||||
sPerm += sPerms[b];
|
||||
Table.SetCell(sPerm, CString(pChan->GetPermCount(sPerms[b])));
|
||||
char cPerm = sPerms[b];
|
||||
Table.SetCell(CString(cPerm), CString(mPerms[cPerm]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-24
@@ -154,20 +154,6 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
case 372: // motd
|
||||
case 376: // end motd
|
||||
m_pUser->AddMotdBuffer(":" + sServer + " " + sCmd + " ", " " + sRest);
|
||||
break;
|
||||
case 471: // :irc.server.net 471 nick #chan :Cannot join channel (+l)
|
||||
case 473: // :irc.server.net 473 nick #chan :Cannot join channel (+i)
|
||||
case 475: // :irc.server.net 475 nick #chan :Cannot join channel (+k)
|
||||
if (m_pUser->IsUserAttached()) {
|
||||
CChan* pChan = m_pUser->FindChan(sRest.substr(0, sRest.find(' ')));
|
||||
|
||||
if ((pChan) && (!pChan->IsOn())) {
|
||||
if (!pChan->DecClientRequests()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 437:
|
||||
// :irc.server.net 437 * badnick :Nick/channel is temporarily unavailable
|
||||
@@ -185,16 +171,6 @@ void CIRCSock::ReadLine(const CString& sData) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 315: {
|
||||
// :irc.server.com 315 yournick #chan :End of /WHO list.
|
||||
CChan* pChan = m_pUser->FindChan(sLine.Token(3));
|
||||
|
||||
if (pChan) {
|
||||
pChan->SetWhoDone();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 331: {
|
||||
// :irc.server.com 331 yournick #chan :No topic is set.
|
||||
CChan* pChan = m_pUser->FindChan(sLine.Token(3));
|
||||
|
||||
Reference in New Issue
Block a user