[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <457975AE.31261.15F652B2@Ulrich.Windl.rkdvmks1.ngate.uni-regensburg.de>
Date: Fri, 08 Dec 2006 14:24:45 +0100
From: "Ulrich Windl" <ulrich.windl@...uni-regensburg.de>
To: linux-kernel@...r.kernel.org
Subject: 2.6.19: slight performance optimization for lib/string.c's strstrip()
Hi,
my apologies for disobeying all the rules for submitting patches, but I'll suggest
a performance optimization for strstrip() in lib/string.c:
Original routine:
char *strstrip(char *s)
{
size_t size;
char *end;
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';
while (*s && isspace(*s))
s++;
return s;
}
EXPORT_SYMBOL(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);
Comments: There's no need to scan the initial banks at the start of the string
twice (using strlen(), and then looking for initial blanks), and we know that the
first character of the string cannot be a blank when we are removing trailing
blanks after having removed leading blanks. Also we do not need to call strlen()
to detect an empty string.
Regards,
Ulrich
-
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