summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-07 10:58:56 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-07 10:58:56 +0000
commit6fef928da861a1c90aca22737e5bc419932702ff (patch)
tree8b915156d05ef9d81c24d82f7d571a2b932f5139
parent148835bea39a0a28625bdab7c7c1a709876b76aa (diff)
*TEST CODE* Faster custom mode set/unset
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3508 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/channels.h17
-rw-r--r--src/channels.cpp83
-rw-r--r--src/helperfuncs.cpp23
3 files changed, 32 insertions, 91 deletions
diff --git a/include/channels.h b/include/channels.h
index 03c636d9b..2e1ede57c 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -72,19 +72,6 @@ class InviteItem : public HostItem
{
};
-
-/** Holds a custom parameter to a module-defined channel mode
- * e.g. for +L this would hold the channel name.
- */
-
-class ModeParameter : public classbase
-{
- public:
- char mode;
- char parameter[MAXBUF];
- char channel[CHANMAX];
-};
-
/** Holds a complete ban list
*/
typedef std::vector<BanItem> BanList;
@@ -110,7 +97,7 @@ class chanrec : public Extensible
/** Custom modes for the channel.
* Plugins may use this field in any way they see fit.
*/
- char custom_modes[MAXMODES]; /* modes handled by modules */
+ char custom_modes[190]; /* modes handled by modules */
/** User list (casted to char*'s to stop forward declaration stuff)
* (chicken and egg scenario!)
@@ -122,7 +109,7 @@ class chanrec : public Extensible
/** Parameters for custom modes
*/
- std::vector<ModeParameter> custom_mode_params;
+ std::map<char,char*> custom_mode_params;
/** Channel topic.
* If this is an empty string, no channel topic is set.
diff --git a/src/channels.cpp b/src/channels.cpp
index f086b9853..3b05cf8ea 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -66,104 +66,59 @@ extern chan_hash chanlist;
using namespace std;
-//std::vector<ModeParameter> custom_mode_params;
-
chanrec* ForceChan(chanrec* Ptr,ucrec &a,userrec* user, int created);
chanrec::chanrec()
{
- *name = *custom_modes = *topic = *setby = *key = 0;
+ *name = *topic = *setby = *key = 0;
created = topicset = limit = binarymodes = 0;
internal_userlist.clear();
+ memset(&custom_modes,0,190);
}
void chanrec::SetCustomMode(char mode,bool mode_on)
{
- if (mode_on)
- {
- char* mptr = this->custom_modes;
- int ssize = 0;
-
- /* Attempt to find the end of the mode string */
- while (*mptr++)
- {
- /* While iterating the mode string, we found that they already have
- * this mode in their list. Abort right now. */
- if (*mptr == mode)
- return;
- /* Increment the string size, saves us doing strlen */
- ssize++;
- }
-
- log(DEBUG,"ssize=%d",ssize);
-
- /* Is there room left in the buffer? If there is append the mode */
- if (ssize < MAXMODES-1)
- {
- *--mptr = mode;
- *++mptr = 0;
- }
-
- log(DEBUG,"Custom mode %c set, modes='%s'",mode,this->custom_modes);
- }
- else
- {
- if (charremove(this->custom_modes,mode))
- {
- log(DEBUG,"Custom mode %c removed: modelist='%s'",mode,this->custom_modes);
- /* Only call this if we found the mode */
- this->SetCustomModeParam(mode,"",false);
- }
- }
+ custom_modes[mode-65] = mode_on;
+ if (!mode_on)
+ this->SetCustomModeParam(mode,"",false);
}
void chanrec::SetCustomModeParam(char mode,char* parameter,bool mode_on)
{
-
log(DEBUG,"SetCustomModeParam called");
- ModeParameter M;
- M.mode = mode;
- strlcpy(M.channel,this->name,CHANMAX);
- strlcpy(M.parameter,parameter,MAXBUF);
+
+ std::map<char,char*>::iterator n = custom_mode_params.find(mode);
+
if (mode_on)
{
log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
- custom_mode_params.push_back(M);
+ if (n == custom_mode_params.end())
+ {
+ custom_mode_params[mode] = strdup(parameter);
+ }
}
else
{
- if (custom_mode_params.size())
+ if (n != custom_mode_params.end())
{
- for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
- {
- if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
- {
- log(DEBUG,"Custom mode parameter %c %s removed",mode,parameter);
- custom_mode_params.erase(i);
- return;
- }
- }
+ free(n->second);
+ custom_mode_params.erase(n);
}
}
}
bool chanrec::IsCustomModeSet(char mode)
{
- return (strchr(this->custom_modes,mode));
+ return custom_modes[mode-65];
}
std::string chanrec::GetModeParameter(char mode)
{
- if (custom_mode_params.size())
+ std::map<char,char*>::iterator n = custom_mode_params.find(mode);
+ if (n != custom_mode_params.end())
{
- for (vector<ModeParameter>::iterator i = custom_mode_params.begin(); i < custom_mode_params.end(); i++)
- {
- if ((i->mode == mode) && (!strcasecmp(this->name,i->channel)))
- {
- return i->parameter;
- }
- }
+ return n->second;
}
return "";
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 854675378..8562be443 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -1198,19 +1198,18 @@ char* chanmodes(chanrec *chan, bool showkey)
sprintf(foo," %lu",(unsigned long)chan->limit);
strlcat(sparam,foo,MAXBUF);
}
- if (*chan->custom_modes)
+ for (int n = 0; n < 190; n++)
{
- for (char* t = chan->custom_modes; *t; t++)
- *offset++ = *t;
- for (int z = 0; chan->custom_modes[z]; z++)
- {
- std::string extparam = chan->GetModeParameter(chan->custom_modes[z]);
- if (extparam != "")
- {
- charlcat(sparam,' ',MAXBUF);
- strlcat(sparam,extparam.c_str(),MAXBUF);
- }
- }
+ if (custom_modes[n])
+ {
+ *offset++ = n+65;
+ std::string extparam = chan->GetModeParameter(n+65);
+ if (extparam != "")
+ {
+ charlcat(sparam,' ',MAXBUF);
+ strlcat(sparam,extparam.c_str(),MAXBUF);
+ }
+ }
}
/* Null terminate scratch */
*offset = '\0';