From b8734f923fe9a859cf29db83db99444787bd1a08 Mon Sep 17 00:00:00 2001 From: om Date: Wed, 8 Mar 2006 00:55:53 +0000 Subject: 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 --- src/mode.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') 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; } -- cgit v1.2.3