You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2022/01/16 13:18:35 UTC

svn commit: r1897122 - in /apr/apr/branches/1.8.x: ./ strings/ strings/apr_cstr.c

Author: ylavic
Date: Sun Jan 16 13:18:34 2022
New Revision: 1897122

URL: http://svn.apache.org/viewvc?rev=1897122&view=rev
Log:
apr_cstr: Follow up to r1897102: Yet better apr_cstr_casecmp[n]().

This ones have a shorter prologue and epilogue (-O2 still).

Dump of assembler code for function apr_cstr_casecmp:
   0x0000000000049fd0 <+0>:     xor    %edx,%edx
   0x0000000000049fd2 <+2>:     lea    0x3d567(%rip),%r8        # 0x87540 <ucharmap>
   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 <apr_cstr_casecmp+46>
   0x0000000000049ffa <+42>:    test   %ecx,%ecx
   0x0000000000049ffc <+44>:    jne    0x49fe0 <apr_cstr_casecmp+16>
   0x0000000000049ffe <+46>:    ret   
End of assembler dump.

Merge r1897121 from trunk.
Submitted by: ylavic

Modified:
    apr/apr/branches/1.8.x/   (props changed)
    apr/apr/branches/1.8.x/strings/   (props changed)
    apr/apr/branches/1.8.x/strings/apr_cstr.c

Propchange: apr/apr/branches/1.8.x/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk:r1897121

Propchange: apr/apr/branches/1.8.x/strings/
------------------------------------------------------------------------------
  Merged /apr/apr/trunk/strings:r1897121

Modified: apr/apr/branches/1.8.x/strings/apr_cstr.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.8.x/strings/apr_cstr.c?rev=1897122&r1=1897121&r2=1897122&view=diff
==============================================================================
--- apr/apr/branches/1.8.x/strings/apr_cstr.c (original)
+++ apr/apr/branches/1.8.x/strings/apr_cstr.c Sun Jan 16 13:18:34 2022
@@ -282,25 +282,27 @@ 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;
 }