summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-14 02:11:32 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2005-12-14 02:11:32 +0000
commitd56539c9abbc2165b29f88c5f62f712497de069b (patch)
tree2da1a7f962c86e0919863452418f90b57fe644c5
parent2bb2422bfc4a0dd02a45bad4578a0aeb48f0b4ad (diff)
tidystring() anal optimisation
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2388 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/message.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/message.cpp b/src/message.cpp
index 8c03e85f2..8adf50793 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -87,32 +87,35 @@ int common_channels(userrec *u, userrec *u2)
return 0;
}
-
void tidystring(char* str)
{
// strips out double spaces before a : parameter
-
+
char temp[MAXBUF];
bool go_again = true;
-
+
if (!str)
- {
return;
- }
-
- while ((str[0] == ' ') && (strlen(str)>0))
- {
+
+ // pointer voodoo++ --w00t
+ while ((*str) && (*str == ' '))
str++;
- }
-
+
while (go_again)
{
bool noparse = false;
unsigned int t = 0, a = 0;
go_again = false;
- while (a < strlen(str))
+ const int lenofstr = strlen(str);
+
+ /*
+ * by caching strlen() of str, we theoretically avoid 3 expensive calls each time this loop
+ * rolls around.. should speed things up a nanosecond or two. ;)
+ */
+
+ while (a < lenofstr)
{
- if ((a<strlen(str)-1) && (noparse==false))
+ if ((a < lenofstr - 1) && (noparse == false))
{
if ((str[a] == ' ') && (str[a+1] == ' '))
{
@@ -121,17 +124,18 @@ void tidystring(char* str)
a++;
}
}
-
- if (a<strlen(str)-1)
+
+ if (a < lenofstr - 1)
{
if ((str[a] == ' ') && (str[a+1] == ':'))
{
noparse = true;
}
}
-
+
temp[t++] = str[a++];
}
+
temp[t] = '\0';
strlcpy(str,temp,MAXBUF);
}