From: Yann Ylavic Date: Sun, 16 Jan 2022 00:45:34 +0000 (+0000) Subject: util: Follow up to r1897101 and r1897105: Yet better ap_cstr_casecmp[n](). X-Git-Tag: 2.5.0-alpha2-ci-test-only~585 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=cbf06f48936268222ee0e1433c790e970831c990;p=thirdparty%2Fapache%2Fhttpd.git util: Follow up to r1897101 and r1897105: Yet better ap_cstr_casecmp[n](). Now with a shorter epilogue. Dump of assembler code for function ap_cstr_casecmp: 0x0000000000049fd0 <+0>: xor %edx,%edx 0x0000000000049fd2 <+2>: lea 0x3d567(%rip),%r8 # 0x87540 0x0000000000049fd9 <+9>: nopl 0x0(%rax) 0x0000000000049fe0 <+16>: movzbl (%rsi,%rdx,1),%eax 0x0000000000049fe4 <+20>: movzbl (%r8,%rax,1),%ecx 0x0000000000049fe9 <+25>: movzbl (%rdi,%rdx,1),%eax 0x0000000000049fed <+29>: add $0x1,%rdx 0x0000000000049ff1 <+33>: movzbl (%r8,%rax,1),%eax 0x0000000000049ff6 <+38>: sub %ecx,%eax 0x0000000000049ff8 <+40>: jne 0x49ffe 0x0000000000049ffa <+42>: test %ecx,%ecx 0x0000000000049ffc <+44>: jne 0x49fe0 0x0000000000049ffe <+46>: ret End of assembler dump. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1897106 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/util.c b/server/util.c index 08eb7c51b0c..9d056627afc 100644 --- a/server/util.c +++ b/server/util.c @@ -3542,11 +3542,11 @@ AP_DECLARE(int) ap_cstr_casecmp(const char *s1, const char *s2) const unsigned char *u1 = (const unsigned char *)s1; const unsigned char *u2 = (const unsigned char *)s2; for (;;) { - const int c1 = ucharmap[*u1++]; const int c2 = ucharmap[*u2++]; - /* Not necessary to test for !c2, this is caught by c1 == c2 */ - if (c1 != c2 || !c1) - return c1 - c2; + const int cmp = (int)ucharmap[*u1++] - c2; + /* Not necessary to test for !c1, this is caught by cmp */ + if (cmp || !c2) + return cmp; } } @@ -3555,11 +3555,11 @@ AP_DECLARE(int) ap_cstr_casecmpn(const char *s1, const char *s2, apr_size_t n) const unsigned char *u1 = (const unsigned char *)s1; const unsigned char *u2 = (const unsigned char *)s2; while (n--) { - const int c1 = ucharmap[*u1++]; const int c2 = ucharmap[*u2++]; - /* Not necessary to test for !c2, this is caught by c1 == c2 */ - if (c1 != c2 || !c1) - return c1 - c2; + 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; }