Suggestion for improvement to strupr and strlwr functions.

J.D McLaughlin J.D.McLaughlin@newcastle.ac.uk
Wed Jan 4 16:25:00 GMT 2006


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.




More information about the Newlib mailing list