Author: brane
Date: Mon Jul  7 17:41:22 2025
New Revision: 1927061

URL: http://svn.apache.org/viewvc?rev=1927061&view=rev
Log:
On the user-defined-authn branch: It turns out that case-folding via a lookup
table is not the fastest way, nor is scanning the data when its length is
already available.

* serf_private.h
  (serf__tolower_inplace): Require the length of the destination data.
   This saves a potentially unnecessary length scan and also does not
   require the data to be NUL-terminated.
* src/syntax.c
  (casefold_table): Throw it away.
  (ct_tolower): Use known properties of the ASCII encoding to get the
   lower-case form.
  (serf__tolower_inplace): Use the new length parameter.
* auth/auth.c
  (store_header_in_dict): Use strcspn() instead of strchr() to find the
   of the scheme name, because it also gives us the length even if there
   are no authn attributes, saving one strlen() later on.
   Use this length to case-fold the hash key.

Modified:
    serf/branches/user-defined-authn/auth/auth.c
    serf/branches/user-defined-authn/serf_private.h
    serf/branches/user-defined-authn/src/syntax.c

Modified: serf/branches/user-defined-authn/auth/auth.c
URL: 
http://svn.apache.org/viewvc/serf/branches/user-defined-authn/auth/auth.c?rev=1927061&r1=1927060&r2=1927061&view=diff
==============================================================================
--- serf/branches/user-defined-authn/auth/auth.c (original)
+++ serf/branches/user-defined-authn/auth/auth.c Mon Jul  7 17:41:22 2025
@@ -248,7 +248,7 @@ static int store_header_in_dict(void *ba
                                 const char *header)
 {
     auth_baton_t *ab = baton;
-    const char *auth_attr;
+    apr_size_t auth_attr_len;
     char *auth_name;
 
     /* We're only interested in xxxx-Authenticate headers. */
@@ -256,15 +256,11 @@ static int store_header_in_dict(void *ba
         return 0;
 
     /* Extract the authentication scheme name.  */
-    auth_attr = strchr(header, ' ');
-    if (auth_attr) {
-        auth_name = apr_pstrmemdup(ab->pool, header, auth_attr - header);
-    }
-    else
-        auth_name = apr_pstrmemdup(ab->pool, header, strlen(header));
+    auth_attr_len = strcspn(header, " ");
+    auth_name = apr_pstrmemdup(ab->pool, header, auth_attr_len);
 
     /* Convert scheme name to lower case to enable case insensitive matching. 
*/
-    serf__tolower_inplace(auth_name);
+    serf__tolower_inplace(auth_name, auth_attr_len);
     apr_hash_set(ab->hdrs, auth_name, APR_HASH_KEY_STRING,
                  apr_pstrdup(ab->pool, header));
 

Modified: serf/branches/user-defined-authn/serf_private.h
URL: 
http://svn.apache.org/viewvc/serf/branches/user-defined-authn/serf_private.h?rev=1927061&r1=1927060&r2=1927061&view=diff
==============================================================================
--- serf/branches/user-defined-authn/serf_private.h (original)
+++ serf/branches/user-defined-authn/serf_private.h Mon Jul  7 17:41:22 2025
@@ -759,8 +759,8 @@ serf__authn_info_t *serf__get_authn_info
 apr_hash_t *serf__parse_authn_parameters(const char *attrs, apr_pool_t *pool);
 
 /* Fold ASCII uppercase letters to lowercase, in place, using the same
-   case-folding table as serf__parse_authn_attributes() does for keys.*/
-void serf__tolower_inplace(char *dst);
+   case-folding serf__parse_authn_parameters() does for keys. */
+void serf__tolower_inplace(char *dst, apr_size_t length);
 
 /* Like serf__tolower_inplace, but allocates a new string from the pool. */
 const char *serf__tolower(const char *src, apr_pool_t *pool);

Modified: serf/branches/user-defined-authn/src/syntax.c
URL: 
http://svn.apache.org/viewvc/serf/branches/user-defined-authn/src/syntax.c?rev=1927061&r1=1927060&r2=1927061&view=diff
==============================================================================
--- serf/branches/user-defined-authn/src/syntax.c (original)
+++ serf/branches/user-defined-authn/src/syntax.c Mon Jul  7 17:41:22 2025
@@ -335,34 +335,15 @@ static APR_INLINE int ct_istoken68(char
     return ct & char_table[0xff & (unsigned char)c];
 }
 
-
-/* Uppercase-lowercase table, also stolen wholesale from Subversion.
-   Folds uppercase ASCII letters into lowercase and ignores the rest. */
-static const unsigned char casefold_table[256] =
-  {
-    /* Identity, except {65:90} => {97:122} */
-      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
-     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
-     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
-     64, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
-    112,113,114,115,116,117,118,119,120,121,122, 91, 92, 93, 94, 95,
-     96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
-    112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
-    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
-    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
-    160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
-    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
-    192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
-    208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
-    224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
-    240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
-  };
-
 /* Fold ASCII to lowercase. */
 static APR_INLINE char ct_tolower(char c)
 {
-    return (char) casefold_table[0xff & (unsigned char)c];
+    /* FIXME: Shouid this just be replaced by apr_tolower?
+              On the other hand, we should only case-fold ASCII letters,
+              while apr_tolower() may be sensitive to the locale. */
+    if (c >= 'A' && c <= 'Z')
+        return (char)(c + 'a' - 'A');
+    return c;
 }
 
 
@@ -509,12 +490,11 @@ apr_hash_t *serf__parse_authn_parameters
 }
 
 
-void serf__tolower_inplace(char *dst)
+void serf__tolower_inplace(char *dst, apr_size_t length)
 {
-    while(*dst) {
-        *dst = ct_tolower(*dst);
-        ++dst;
-    }
+    apr_size_t i;
+    for (i = 0; i < length; ++i)
+        dst[i] = ct_tolower(dst[i]);
 }
 
 


Reply via email to