apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject cvs commit: apr/strings apr_strings.c
Date Fri, 28 Sep 2001 03:43:05 GMT
ianh        01/09/27 20:43:05

  Modified:    .        CHANGES
               strings  apr_strings.c
  Log:
  optimize apr_pstrcat by storing the lengths of the first 6 strings
  (changed const to #define as suggested, and so that it compiles on NT)
  
  Submitted by:	Brian Pane <bpane@pacbell.net>
  Reviewed by:	Ian Holsman
  
  Revision  Changes    Path
  1.162     +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.161
  retrieving revision 1.162
  diff -u -r1.161 -r1.162
  --- CHANGES	2001/09/26 20:55:33	1.161
  +++ CHANGES	2001/09/28 03:43:04	1.162
  @@ -1,5 +1,8 @@
   Changes with APR b1  
   
  +  *) Optimize apr_pstrcat by caching lengths of first 6 strings
  +     [Brian Pane <bpane@pacbell.net>]
  +
     *) Add pool accessors to the apr_thread_mutex_t datatype.
        [Aaron Bannert <aaron@clove.org>]
   
  
  
  
  1.21      +18 -1     apr/strings/apr_strings.c
  
  Index: apr_strings.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_strings.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- apr_strings.c	2001/07/26 03:11:00	1.20
  +++ apr_strings.c	2001/09/28 03:43:05	1.21
  @@ -65,6 +65,9 @@
   #include <stddef.h> /* NULL */
   #endif
   
  +/** this is used to cache lengths in apr_pstrcat */
  +#define MAX_SAVED_LENGTHS  6
  +
   APR_DECLARE(char *) apr_pstrdup(apr_pool_t *a, const char *s)
   {
       char *res;
  @@ -110,6 +113,8 @@
   APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *a, ...)
   {
       char *cp, *argp, *res;
  +    apr_size_t saved_lengths[MAX_SAVED_LENGTHS];
  +    int nargs = 0;
   
       /* Pass one --- find length of required string */
   
  @@ -119,7 +124,11 @@
       va_start(adummy, a);
   
       while ((cp = va_arg(adummy, char *)) != NULL) {
  -        len += strlen(cp);
  +        apr_size_t cplen = strlen(cp);
  +        if (nargs < MAX_SAVED_LENGTHS) {
  +            saved_lengths[nargs++] = cplen;
  +        }
  +        len += cplen;
       }
   
       va_end(adummy);
  @@ -133,8 +142,16 @@
   
       va_start(adummy, a);
   
  +    nargs = 0;
       while ((argp = va_arg(adummy, char *)) != NULL) {
           len = strlen(argp);
  +        if (nargs < MAX_SAVED_LENGTHS) {
  +            len = saved_lengths[nargs++];
  +        }
  +        else {
  +            len = strlen(argp);
  +        }
  + 
           memcpy(cp, argp, len);
           cp += len;
       }
  
  
  

Mime
View raw message