summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-08 00:55:53 +0000
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-03-08 00:55:53 +0000
commitb8734f923fe9a859cf29db83db99444787bd1a08 (patch)
tree1391fbbb59fa0ab674e4f5a703b122873956c7cc
parent0b6667568e88c2d76ecd9bfc5a4445b88435b54e (diff)
Speed up and deuglify the second part of CompressModes(), stop it searching for a character three times when it only needs to once, stop it allocating an ugly static char[2] it didn't need, and stop it creating a std::string it didn't need either
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3538 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/mode.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/mode.cpp b/src/mode.cpp
index 1b59a1352..eb3deb228 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -405,6 +405,7 @@ std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
bool active[127];
memset(counts,0,sizeof(counts));
memset(active,0,sizeof(active));
+
for (unsigned int i = 0; i < modes.length(); i++)
{
if ((modes[i] == '+') || (modes[i] == '-'))
@@ -429,20 +430,17 @@ std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
{
if ((counts[j] > 1) && (active[j] == true))
{
- static char v[2];
- v[0] = (unsigned char)j;
- v[1] = '\0';
- std::string mode_str = v;
- std::string::size_type pos = modes.find(mode_str);
- if (pos != std::string::npos)
+ std::string::size_type pos;
+
+ while((pos = modes.find((unsigned char)j)) != std::string::npos)
{
- log(DEBUG,"all occurances of mode %c to be deleted...",(unsigned char)j);
- while (modes.find(mode_str) != std::string::npos)
- modes.erase(modes.find(mode_str),1);
- log(DEBUG,"New mode line: %s",modes.c_str());
+ log(DEBUG, "Deleting occurence of mode %c...", (unsigned char)j);
+ modes.erase(pos, 1);
+ log(DEBUG,"New mode line: %s", modes.c_str());
}
}
}
+
return modes;
}