apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr/tables apr_tables.c
Date Sun, 10 Mar 2002 17:20:27 GMT
brianp      02/03/10 09:20:26

  Modified:    .        CHANGES
               tables   apr_tables.c
  Log:
  Optimized away the initialization of newly allocated table
  elements to NULL in table_push(), because this data always
  gets overwritten immediately after the table_push() call.
  Also eliminated the zero-fill of bytes that are immediately
  overwritten in the branch of apr_array_push() that resizes
  the array.
  
  Revision  Changes    Path
  1.235     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.234
  retrieving revision 1.235
  diff -u -r1.234 -r1.235
  --- CHANGES	9 Mar 2002 19:26:13 -0000	1.234
  +++ CHANGES	10 Mar 2002 17:20:26 -0000	1.235
  @@ -1,5 +1,9 @@
   Changes with APR b1
   
  +  *) Small table performance optimization: eliminate the
  +     zero-fill of newly allocated elements when expanding
  +     a table's size. [Brian Pane]
  +
     *) Allow APR to install its generated libtool(s) via the 
        --with-installbuilddir option (defaults to ${datadir}/build).
        [Justin Erenkrantz]
  
  
  
  1.24      +22 -3     apr/tables/apr_tables.c
  
  Index: apr_tables.c
  ===================================================================
  RCS file: /home/cvs/apr/tables/apr_tables.c,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- apr_tables.c	13 Feb 2002 17:57:12 -0000	1.23
  +++ apr_tables.c	10 Mar 2002 17:20:26 -0000	1.24
  @@ -128,7 +128,26 @@
           int new_size = (arr->nalloc <= 0) ? 1 : arr->nalloc * 2;
           char *new_data;
   
  -        new_data = apr_pcalloc(arr->pool, arr->elt_size * new_size);
  +        new_data = apr_palloc(arr->pool, arr->elt_size * new_size);
  +
  +        memcpy(new_data, arr->elts, arr->nalloc * arr->elt_size);
  +        memset(new_data + arr->nalloc * arr->elt_size, 0,
  +               arr->elt_size * (new_size - arr->nalloc));
  +        arr->elts = new_data;
  +        arr->nalloc = new_size;
  +    }
  +
  +    ++arr->nelts;
  +    return arr->elts + (arr->elt_size * (arr->nelts - 1));
  +}
  +
  +static void *apr_array_push_noclear(apr_array_header_t *arr)
  +{
  +    if (arr->nelts == arr->nalloc) {
  +        int new_size = (arr->nalloc <= 0) ? 1 : arr->nalloc * 2;
  +        char *new_data;
  +
  +        new_data = apr_palloc(arr->pool, arr->elt_size * new_size);
   
           memcpy(new_data, arr->elts, arr->nalloc * arr->elt_size);
           arr->elts = new_data;
  @@ -331,10 +350,10 @@
       if (t->a.nelts == t->a.nalloc) {
           return NULL;
       }
  -    return (apr_table_entry_t *) apr_array_push(&t->a);
  +    return (apr_table_entry_t *) apr_array_push_noclear(&t->a);
   }
   #else /* MAKE_TABLE_PROFILE */
  -#define table_push(t)	((apr_table_entry_t *) apr_array_push(&(t)->a))
  +#define table_push(t)	((apr_table_entry_t *) apr_array_push_noclear(&(t)->a))
   #endif /* MAKE_TABLE_PROFILE */
   
   
  
  
  

Mime
View raw message