This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Suggestion for improvement to strupr and strlwr functions.
- From: "J.D McLaughlin" <J dot D dot McLaughlin at newcastle dot ac dot uk>
- To: newlib at sources dot redhat dot com
- Date: Wed, 4 Jan 2006 16:25:29 -0000 (GMT)
- Subject: Suggestion for improvement to strupr and strlwr functions.
Hi,
Examining the source code to C's string functions, I noticed that strupr()
called toupper() on each char in turn if isupper() returned false(or maybe
if islower() returned true). However, the toupper() function itself calls
this function to check beforehand whether or not it needs to do anything,
and vice versa for the strlwr() function. It looks as if it would be
better to avoid the duplicated check by just calling toupper for every
character in the array - although I could be wrong, if the string had less
than half it's characters in lower case, it would be constantly calling
toupper and isupper for characters where only isupper was needed.
I'm not sure what the statistical properties are of strings generally
input to strupr, but I thought I'd share this idea in case in the
average-case scenario it's more efficient.
James McLaughlin.