diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2009-04-23 18:11:22 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2009-04-23 18:11:22 +0000 |
commit | 5921804481c346f032a24c19fc294cc5690e0f3b (patch) | |
tree | 3e71f94ad0832136ea7da2bfd4d0ad3c1ec1398c | |
parent | bbb9d4fde31f44a70a6fb42181dc86cb91791d7e (diff) | |
download | newlib-5921804481c346f032a24c19fc294cc5690e0f3b.zip newlib-5921804481c346f032a24c19fc294cc5690e0f3b.tar.gz newlib-5921804481c346f032a24c19fc294cc5690e0f3b.tar.bz2 |
2009-04-23 Mike Burgess <wizardsguild@earthlink.net>
* libc/string/strcasecmp.c: Optimized rewrite.
* libc/string/strncasecmp.c: Fix description.
* libc/string/strlwr.c: Avoid passing signed char to tolower.
* libc/string/strupr.c: Avoid passing signed char to tolower.
-rw-r--r-- | newlib/ChangeLog | 7 | ||||
-rw-r--r-- | newlib/libc/string/strcasecmp.c | 18 | ||||
-rw-r--r-- | newlib/libc/string/strlwr.c | 16 | ||||
-rw-r--r-- | newlib/libc/string/strncasecmp.c | 2 | ||||
-rw-r--r-- | newlib/libc/string/strupr.c | 19 |
5 files changed, 33 insertions, 29 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog index fce8f2a..c1e1d39 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2009-04-23 Mike Burgess <wizardsguild@earthlink.net> + + * libc/string/strcasecmp.c: Optimized rewrite. + * libc/string/strncasecmp.c: Fix description. + * libc/string/strlwr.c: Avoid passing signed char to tolower. + * libc/string/strupr.c: Avoid passing signed char to tolower. + 2009-04-23 Paul Brook <paul@codesourcery.com> Kazu Hirata <kazu@codesourcery.com> diff --git a/newlib/libc/string/strcasecmp.c b/newlib/libc/string/strcasecmp.c index f96f7f5..73cf866 100644 --- a/newlib/libc/string/strcasecmp.c +++ b/newlib/libc/string/strcasecmp.c @@ -22,7 +22,7 @@ DESCRIPTION RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after - both are converted to uppercase), <<strcasecmp>> returns a + both are converted to lowercase), <<strcasecmp>> returns a number greater than zero. If the two strings match, <<strcasecmp>> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <<strcasecmp>> returns a @@ -35,7 +35,7 @@ PORTABILITY tolower() from elsewhere in this library. QUICKREF - strcasecmp + strcasecmp */ #include <string.h> @@ -46,11 +46,15 @@ _DEFUN (strcasecmp, (s1, s2), _CONST char *s1 _AND _CONST char *s2) { - while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) + _CONST unsigned char *ucs1 = (_CONST unsigned char *) s1; + _CONST unsigned char *ucs2 = (_CONST unsigned char *) s2; + int d = 0; + for ( ; ; ) { - s1++; - s2++; + _CONST int c1 = tolower(*ucs1++); + _CONST int c2 = tolower(*ucs2++); + if (((d = c1 - c2) != 0) || (c2 == '\0')) + break; } - - return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2); + return d; } diff --git a/newlib/libc/string/strlwr.c b/newlib/libc/string/strlwr.c index 47096d4..3b73dba 100644 --- a/newlib/libc/string/strlwr.c +++ b/newlib/libc/string/strlwr.c @@ -34,17 +34,13 @@ QUICKREF #include <ctype.h> char * -strlwr (a) - char *a; +_DEFUN (strlwr, (s), + char *s) { - char *ret = a; - - while (*a != '\0') + unsigned char *ucs = (unsigned char *) s; + for ( ; *ucs != '\0'; ucs++) { - if (isupper (*a)) - *a = tolower (*a); - ++a; + *ucs = tolower(*ucs); } - - return ret; + return s; } diff --git a/newlib/libc/string/strncasecmp.c b/newlib/libc/string/strncasecmp.c index c2eb5b8..6909018 100644 --- a/newlib/libc/string/strncasecmp.c +++ b/newlib/libc/string/strncasecmp.c @@ -24,7 +24,7 @@ DESCRIPTION RETURNS If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after - both are converted to uppercase), <<strncasecmp>> returns a + both are converted to lowercase), <<strncasecmp>> returns a number greater than zero. If the two strings are equivalent, <<strncasecmp>> returns zero. If <<*<[a]>>> sorts lexicographically before <<*<[b]>>>, <<strncasecmp>> returns a diff --git a/newlib/libc/string/strupr.c b/newlib/libc/string/strupr.c index 3f346b8..350618e 100644 --- a/newlib/libc/string/strupr.c +++ b/newlib/libc/string/strupr.c @@ -27,23 +27,20 @@ PORTABILITY <<strupr>> requires no supporting OS subroutines. QUICKREF - strupr */ + strupr +*/ #include <string.h> #include <ctype.h> char * -strupr (a) - char *a; +_DEFUN (strupr, (s), + char *s) { - char *ret = a; - - while (*a != '\0') + unsigned char *ucs = (unsigned char *) s; + for ( ; *ucs != '\0'; ucs++) { - if (islower (*a)) - *a = toupper (*a); - ++a; + *ucs = toupper(*ucs); } - - return ret; + return s; } |