summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-09 00:25:18 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-09 00:25:18 +0000
commitbe70931a50f23c68e055602facce5736775f3fab (patch)
tree5ab53e604456abb30bcb06185bd09414117d4943
parent7a9d31a46328de9c12e09c6f5620d39251efdf34 (diff)
Cache channel max bans value to save an O(n) loop of match() on every ban (etc) add
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6267 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/channels.h8
-rw-r--r--include/inspircd.h5
-rw-r--r--src/channels.cpp17
-rw-r--r--src/cmd_rehash.cpp1
-rw-r--r--src/inspircd.cpp8
-rw-r--r--src/modules.cpp1
-rw-r--r--src/modules/m_spanningtree.cpp1
7 files changed, 39 insertions, 2 deletions
diff --git a/include/channels.h b/include/channels.h
index a85e69dd1..17e7364a4 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -124,6 +124,10 @@ class chanrec : public Extensible
prefixlist prefixes;
+ /** Maximum number of bans (cached)
+ */
+ int maxbans;
+
public:
/** The channels name.
*/
@@ -510,6 +514,10 @@ class chanrec : public Extensible
*/
bool IsBanned(userrec* user);
+ /** Clears the cached max bans value
+ */
+ void ResetMaxBans();
+
/** Destructor for chanrec
*/
virtual ~chanrec() { /* stub */ }
diff --git a/include/inspircd.h b/include/inspircd.h
index 0e53ce1c4..1931c3987 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -1169,6 +1169,11 @@ class InspIRCd : public classbase
*/
void RehashUsersAndChans();
+ /** Resets the cached max bans value on all channels.
+ * Called by rehash.
+ */
+ void ResetMaxBans();
+
/** Begin execution of the server.
* NOTE: this function NEVER returns. Internally,
* after performing some initialisation routines,
diff --git a/src/channels.cpp b/src/channels.cpp
index 4aea42ac8..4b1bc5309 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -22,7 +22,7 @@
chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance)
{
*name = *topic = *setby = *key = 0;
- created = topicset = limit = 0;
+ maxbans = created = topicset = limit = 0;
memset(&modes,0,64);
age = ServerInstance->Time(true);
}
@@ -870,16 +870,29 @@ void chanrec::UserList(userrec *user)
long chanrec::GetMaxBans()
{
+ /* Return the cached value if there is one */
+ if (this->maxbans)
+ return this->maxbans;
+
+ /* If there isnt one, we have to do some O(n) hax to find it the first time. (ick) */
for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
{
if (match(this->name,n->first.c_str()))
{
+ this->maxbans = n->second;
return n->second;
}
}
- return 64;
+
+ /* Screw it, just return the default of 64 */
+ this->maxbans = 64;
+ return this->maxbans;
}
+void chanrec::ResetMaxBans()
+{
+ this->maxbans = 0;
+}
/* returns the status character for a given user on a channel, e.g. @ for op,
* % for halfop etc. If the user has several modes set, the highest mode
diff --git a/src/cmd_rehash.cpp b/src/cmd_rehash.cpp
index 8154c5b92..d942255f3 100644
--- a/src/cmd_rehash.cpp
+++ b/src/cmd_rehash.cpp
@@ -41,6 +41,7 @@ CmdResult cmd_rehash::Handle (const char** parameters, int pcnt, userrec *user)
FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
ServerInstance->Config->Read(false,user);
ServerInstance->Res->Rehash();
+ ServerInstance->ResetMaxBans();
}
if (old_disabled != ServerInstance->Config->DisabledCommands)
InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index efb842f60..b75a91715 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -148,10 +148,18 @@ void InspIRCd::Rehash(int status)
SI->RehashUsersAndChans();
FOREACH_MOD_I(SI, I_OnGarbageCollect, OnGarbageCollect());
SI->Config->Read(false,NULL);
+ SI->ResetMaxBans();
SI->Res->Rehash();
FOREACH_MOD_I(SI,I_OnRehash,OnRehash(NULL,""));
}
+void InspIRCd::ResetMaxBans()
+{
+ for (chan_hash::const_iterator i = chanlist->begin(); i != chanlist->end(); i++)
+ i->second->ResetMaxBans();
+}
+
+
/** Because hash_map doesnt free its buckets when we delete items (this is a 'feature')
* we must occasionally rehash the hash (yes really).
* We do this by copying the entries from the old hash to a new hash, causing all
diff --git a/src/modules.cpp b/src/modules.cpp
index 8d5ca846f..211ce9853 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -348,6 +348,7 @@ void InspIRCd::RehashServer()
this->WriteOpers("*** Rehashing config file");
this->RehashUsersAndChans();
this->Config->Read(false,NULL);
+ this->ResetMaxBans();
this->Res->Rehash();
}
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 8fee962fa..871675ed6 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -5158,6 +5158,7 @@ class ModuleSpanningTree : public Module
}
}
Utils->ReadConfiguration(false);
+ InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
}
// note: the protocol does not allow direct umode +o except