summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-08 01:50:38 +0000
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-08 01:50:38 +0000
commit7d3c3c785207dbcb18febfb6b28cfee8bb52dbb8 (patch)
tree08e3655c3cee34ef6f124379ff96cd3b7f516e68 /src
parentbdff885711ae10ad3d15470cd7af744985c88f91 (diff)
More optimisations, memory saving, use the char* loop everywhere else seems to love so much, use short rather than int to save a little more ram
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3541 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/mode.cpp43
1 files changed, 23 insertions, 20 deletions
diff --git a/src/mode.cpp b/src/mode.cpp
index 724a54693..7d5a81d69 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -397,33 +397,36 @@ char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status)
return NULL;
}
-// tidies up redundant modes, e.g. +nt-nt+i becomes +-+i,
-// a section further down the chain tidies up the +-+- crap.
+
+/** ModeParser::CompressModes()
+ * Tidies up redundant modes,
+ * e.g. +nt-nt+i becomes +-+i
+ * A section further down the chain tidies up the +-+- crap.
+ */
std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
{
- int counts[127];
+ /*
+ * OK, iterate over the mode string and count how many times a certain mode appears in it.
+ * Then, erase all instances of any character that appears more than once.
+ * This only operates on modes with no parameters, you can still +v-v+v-v+v-v to your heart's content.
+ */
+
+ /* Do we really need an int here? Can you fit enough modes in a line to overflow a short? */
+ short counts[127];
bool active[127];
- memset(counts,0,sizeof(counts));
- memset(active,0,sizeof(active));
+ memset(counts, 0, sizeof(counts));
+ memset(active, 0, sizeof(active));
- for (unsigned int i = 0; i < modes.length(); i++)
+ for(unsigned char* i = (unsigned char*)modes.c_str(); *i; i++)
{
- if ((modes[i] == '+') || (modes[i] == '-'))
+ if((*i == '+') || (*i == '-'))
continue;
- if (channelmodes)
- {
- if ((strchr("itnmsp",modes[i])) || ((ModeDefined(modes[i],MT_CHANNEL)) && (ModeDefinedOn(modes[i],MT_CHANNEL)==0) && (ModeDefinedOff(modes[i],MT_CHANNEL)==0)))
- {
- log(DEBUG,"Tidy mode %c",modes[i]);
- counts[(unsigned int)modes[i]]++;
- active[(unsigned int)modes[i]] = true;
- }
- }
- else
+
+ if(!channelmodes || (channelmodes && (strchr("itnmsp", *i) || (ModeDefined(*i, MT_CHANNEL) && !ModeDefinedOn(*i,MT_CHANNEL) && !ModeDefinedOff(*i,MT_CHANNEL)))))
{
- log(DEBUG,"Tidy mode %c",modes[i]);
- counts[(unsigned int)modes[i]]++;
- active[(unsigned int)modes[i]] = true;
+ log(DEBUG,"Tidy mode %c", *i);
+ counts[*i]++;
+ active[*i] = true;
}
}