summaryrefslogtreecommitdiff
path: root/strings/apr_cstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'strings/apr_cstr.c')
-rw-r--r--strings/apr_cstr.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/strings/apr_cstr.c b/strings/apr_cstr.c
index 8ee55b54b..e65077a6e 100644
--- a/strings/apr_cstr.c
+++ b/strings/apr_cstr.c
@@ -282,26 +282,28 @@ static const unsigned char ucharmap[256] = {
APR_DECLARE(int) apr_cstr_casecmp(const char *s1, const char *s2)
{
- apr_size_t i = 0;
- for (;; ++i) {
- const int c1 = ucharmap[(unsigned char)s1[i]];
- const int c2 = ucharmap[(unsigned char)s2[i]];
- /* Not necessary to test for !c2, this is caught by c1 != c2 */
- if (c1 != c2 || !c1)
- return c1 - c2;
+ const unsigned char *u1 = (const unsigned char *)s1;
+ const unsigned char *u2 = (const unsigned char *)s2;
+ for (;;) {
+ const int c2 = ucharmap[*u2++];
+ const int cmp = (int)ucharmap[*u1++] - c2;
+ /* Not necessary to test for !c1, this is caught by cmp */
+ if (cmp || !c2)
+ return cmp;
}
}
APR_DECLARE(int) apr_cstr_casecmpn(const char *s1, const char *s2,
apr_size_t n)
{
- apr_size_t i = 0;
- for (; i < n; ++i) {
- const int c1 = ucharmap[(unsigned char)s1[i]];
- const int c2 = ucharmap[(unsigned char)s2[i]];
- /* Not necessary to test for !c2, this is caught by c1 != c2 */
- if (c1 != c2 || !c1)
- return c1 - c2;
+ const unsigned char *u1 = (const unsigned char *)s1;
+ const unsigned char *u2 = (const unsigned char *)s2;
+ while (n--) {
+ const int c2 = ucharmap[*u2++];
+ const int cmp = (int)ucharmap[*u1++] - c2;
+ /* Not necessary to test for !c1, this is caught by cmp */
+ if (cmp || !c2)
+ return cmp;
}
return 0;
}