[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20061211000254.32230.qmail@web55609.mail.re4.yahoo.com>
Date: Sun, 10 Dec 2006 16:02:54 -0800 (PST)
From: Amit Choudhary <amit2030@...oo.com>
To: Linux Kernel <linux-kernel@...r.kernel.org>
Subject: Re: 2.6.19: slight performance optimization for lib/string.c's strstrip()
> Suggested replacement:
>
> char *strstrip(char *s)
> {
> size_t size;
> char *end;
>
> while (*s && isspace(*s))
> s++;
> if (!*s)
> return s;
> size = strlen(s);
>
> end = s + size - 1;
> while (end > s && isspace(*end))
> end--;
> *(end + 1) = '\0';
>
> return s;
> }
> EXPORT_SYMBOL(strstrip);
How about this:
char *strstrip(char *s)
{
size_t less = 0;
char c = 0;
char *e = NULL;
while ((c=*s) && isspace(c))
s++;
if (!c)
return s;
e = s;
while (c=*e) {
less = isspace(c) ? (less + 1) : 0;
e++;
}
*(e-less) = 0;
return s;
}
1. no need to scan trailing spaces twice (once in strlen and then again).
2. pointer dereference only once per loop rather than multiple times.
Regards,
Amit
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists