]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Cache channel max bans value to save an O(n) loop of match() on every ban (etc) add
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 9 Jan 2007 00:25:18 +0000 (00:25 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 9 Jan 2007 00:25:18 +0000 (00:25 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6267 e03df62e-2008-0410-955e-edbf42e46eb7

include/channels.h
include/inspircd.h
src/channels.cpp
src/cmd_rehash.cpp
src/inspircd.cpp
src/modules.cpp
src/modules/m_spanningtree.cpp

index a85e69dd1ec02a02415196a033672910ea7022a6..17e7364a42919eab3ed829887c8cb0a8f7d94d8f 100644 (file)
@@ -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 */ }
index 0e53ce1c400b0b2af6df42acf97572de0fa94d74..1931c3987df4a4bbde890c7018db1732cb34ee5d 100644 (file)
@@ -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,
index 4aea42ac8a6d18404ef43788cd4e2ec1736067e6..4b1bc530914c8c37e9238bb397b978f1f2406d33 100644 (file)
@@ -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
index 8154c5b923d02f97cb42a9f9f1956316a13e69da..d942255f350b6918fad7820abdd5955d932e9197 100644 (file)
@@ -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);
index efb842f60ac1e473241df1022bd8bd9c04e003ec..b75a91715c8ffeb613f4ab17d8b97d960402565e 100644 (file)
@@ -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
index 8d5ca846f1349257447960ecfffb2afa691cff55..211ce9853693ae67b603838aa8851f1937242aa6 100644 (file)
@@ -348,6 +348,7 @@ void InspIRCd::RehashServer()
        this->WriteOpers("*** Rehashing config file");
        this->RehashUsersAndChans();
        this->Config->Read(false,NULL);
+       this->ResetMaxBans();
        this->Res->Rehash();
 }
 
index 8fee962faebf68c6fc0b7a4b40e70a3d2f5f497c..871675ed6afc65d03c0ed822de801aa82ca9cf92 100644 (file)
@@ -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