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
This commit is contained in:
om 2006-03-08 00:55:53 +00:00
parent 0b6667568e
commit b8734f923f

View File

@ -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;
}