httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grega...@apache.org
Subject cvs commit: httpd-2.0/server protocol.c
Date Tue, 24 Jul 2001 22:55:29 GMT
gregames    01/07/24 15:55:29

  Modified:    .        CHANGES
               include  apr_strings.h
               network_io/unix inet_ntop.c
               strings  apr_strings.c
               .        CHANGES
               modules/loggers mod_log_config.c
               server   protocol.c
  Log:
  Reduce CPU consumption in conv_10 function, used to format "%d" by apr_*printf
  
  This includes two changes to APR:
    * new functions apr_itoa, apr_ltoa, and apr_off_t_toa
      that provide itoa-type functionality based on pools
    * Inline code in inet_ntop4 to replace sprintf for converting
      binary IP addresses into dotted-decimal format
  
  and two changes to Apache:
    * use the apr_itoa functions in setting the content length,
      in place of apr_psprintf
    * use the apr_itoa functions to replace frequent uses of
      'sprintf("%d",...)' in mod_log_config.
  
  Submitted by: Brian Pane
  Reviewed by:  Dean Gaudet, Greg Ames
  
  Revision  Changes    Path
  1.127     +4 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.126
  retrieving revision 1.127
  diff -u -r1.126 -r1.127
  --- CHANGES	2001/07/24 05:16:32	1.126
  +++ CHANGES	2001/07/24 22:55:28	1.127
  @@ -1,5 +1,9 @@
   Changes with APR b1  
   
  +  *) Provide new number conversion functions apr_itoa, apr_ltoa, and 
  +     apr_off_t_toa, and inline code in inet_ntop4, to reduce CPU
  +     consumption. [Brian Pane]
  +
     *) Updated APR to pass the thread worker_function prototype 
        (apr_thread_start_t) two parameters, the apr private data 
        (apr_thread_t*) and the application private data (void*).  
  
  
  
  1.19      +27 -0     apr/include/apr_strings.h
  
  Index: apr_strings.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_strings.h,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- apr_strings.h	2001/06/15 15:08:22	1.18
  +++ apr_strings.h	2001/07/24 22:55:28	1.19
  @@ -279,6 +279,33 @@
   APR_DECLARE(int) apr_vsnprintf(char *buf, apr_size_t len, const char *format,
                                  va_list ap);
   
  +/**
  + * create a string representation of an int, allocated from a pool
  + * @param p The pool from which to allocate
  + * @param n The number to format
  + * @return The string representation of the number
  + * @deffunc int apr_itoa(apr_pool_t *p, int n)
  + */
  +APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n);
  +
  +/**
  + * create a string representation of a long, allocated from a pool
  + * @param p The pool from which to allocate
  + * @param n The number to format
  + * @return The string representation of the number
  + * @deffunc int apr_ltoa(apr_pool_t *p, long n)
  + */
  +APR_DECLARE(char *) apr_ltoa(apr_pool_t *p, long n);
  +
  +/**
  + * create a string representation of an apr_off_t, allocated from a pool
  + * @param p The pool from which to allocate
  + * @param n The number to format
  + * @return The string representation of the number
  + * @deffunc int apr_ltoa(apr_pool_t *p, apr_off_t n)
  + */
  +APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, apr_off_t n);
  +
   #ifdef __cplusplus
   }
   #endif
  
  
  
  1.11      +24 -7     apr/network_io/unix/inet_ntop.c
  
  Index: inet_ntop.c
  ===================================================================
  RCS file: /home/cvs/apr/network_io/unix/inet_ntop.c,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- inet_ntop.c	2001/06/06 15:22:04	1.10
  +++ inet_ntop.c	2001/07/24 22:55:28	1.11
  @@ -99,15 +99,32 @@
   static const char *
   inet_ntop4(const unsigned char *src, char *dst, apr_size_t size)
   {
  -	static const char fmt[] = "%u.%u.%u.%u";
  -	char tmp[sizeof "255.255.255.255"];
  +	const int MIN_SIZE = 16; /* space for 255.255.255.255\0 */
  +	int n = 0;
  +	char *next = dst;
   
  -	if (apr_snprintf(tmp, sizeof tmp, fmt, src[0], src[1], src[2], src[3]) > (int)size)
{
  -		errno = ENOSPC;
  -		return (NULL);
  +	if (size < MIN_SIZE) {
  +	    errno = ENOSPC;
  +	    return NULL;
   	}
  -	strcpy(dst, tmp);
  -	return (dst);
  +	do {
  +	    unsigned char u = *src++;
  +	    if (u > 99) {
  +		*next++ = '0' + u/100;
  +		u %= 100;
  +		*next++ = '0' + u/10;
  +		u %= 10;
  +	    }
  +	    else if (u > 9) {
  +		*next++ = '0' + u/10;
  +		u %= 10;
  +	    }
  +	    *next++ = '0' + u;
  +	    *next++ = '.';
  +	    n++;
  +	} while (n < 4);
  +	*--next = 0;
  +	return dst;
   }
   
   #if APR_HAVE_IPV6
  
  
  
  1.16      +72 -0     apr/strings/apr_strings.c
  
  Index: apr_strings.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_strings.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- apr_strings.c	2001/06/20 19:50:29	1.15
  +++ apr_strings.c	2001/07/24 22:55:28	1.16
  @@ -163,3 +163,75 @@
       return NULL;
   }
   #endif
  +
  +APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n)
  +{
  +    const int BUFFER_SIZE = sizeof(int) * 3 + 2;
  +    char *buf = apr_palloc(p, BUFFER_SIZE);
  +    char *start = buf + BUFFER_SIZE - 1;
  +    int negative;
  +    if (n < 0) {
  +	negative = 1;
  +	n = -n;
  +    }
  +    else {
  +	negative = 0;
  +    }
  +    *start = 0;
  +    do {
  +	*--start = '0' + (n % 10);
  +	n /= 10;
  +    } while (n);
  +    if (negative) {
  +	*--start = '-';
  +    }
  +    return start;
  +}
  +
  +APR_DECLARE(char *) apr_ltoa(apr_pool_t *p, long n)
  +{
  +    const int BUFFER_SIZE = sizeof(long) * 3 + 2;
  +    char *buf = apr_palloc(p, BUFFER_SIZE);
  +    char *start = buf + BUFFER_SIZE - 1;
  +    int negative;
  +    if (n < 0) {
  +	negative = 1;
  +	n = -n;
  +    }
  +    else {
  +	negative = 0;
  +    }
  +    *start = 0;
  +    do {
  +	*--start = '0' + (n % 10);
  +	n /= 10;
  +    } while (n);
  +    if (negative) {
  +	*--start = '-';
  +    }
  +    return start;
  +}
  +
  +APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, long n)
  +{
  +    const int BUFFER_SIZE = sizeof(apr_off_t) * 3 + 2;
  +    char *buf = apr_palloc(p, BUFFER_SIZE);
  +    char *start = buf + BUFFER_SIZE - 1;
  +    int negative;
  +    if (n < 0) {
  +	negative = 1;
  +	n = -n;
  +    }
  +    else {
  +	negative = 0;
  +    }
  +    *start = 0;
  +    do {
  +	*--start = '0' + (n % 10);
  +	n /= 10;
  +    } while (n);
  +    if (negative) {
  +	*--start = '-';
  +    }
  +    return start;
  +}
  
  
  
  1.257     +5 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.256
  retrieving revision 1.257
  diff -u -r1.256 -r1.257
  --- CHANGES	2001/07/24 14:36:28	1.256
  +++ CHANGES	2001/07/24 22:55:28	1.257
  @@ -1,4 +1,9 @@
   Changes with Apache 2.0.22-dev
  +
  +  *) Use new APR number conversion functions to reduce CPU consumption 
  +     when setting the content length, and in mod_log_config.
  +     [Brian Pane]
  +     
     *) Fix problem reported by Taketo Kabe <kabe@sra-tohoku.co.jp>
        where HEAD response headers were being repeated twice for
        files greater than 32K bytes (4*AP_MIN_BYTES_TO_WRITE). This
  
  
  
  1.63      +2 -2      httpd-2.0/modules/loggers/mod_log_config.c
  
  Index: mod_log_config.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
  retrieving revision 1.62
  retrieving revision 1.63
  diff -u -r1.62 -r1.63
  --- mod_log_config.c	2001/07/18 19:41:20	1.62
  +++ mod_log_config.c	2001/07/24 22:55:29	1.63
  @@ -284,7 +284,7 @@
   
   static char *format_integer(apr_pool_t *p, int i)
   {
  -    return apr_psprintf(p, "%d", i);
  +    return apr_itoa(p, i);
   }
   
   static char *pfmt(apr_pool_t *p, int i)
  @@ -381,7 +381,7 @@
           return "-";
       }
       else {
  -	return apr_psprintf(r->pool, "%ld", r->bytes_sent);
  +	return apr_ltoa(r->pool, r->bytes_sent);
       }
   }
   
  
  
  
  1.33      +1 -1      httpd-2.0/server/protocol.c
  
  Index: protocol.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/server/protocol.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- protocol.c	2001/07/24 21:33:44	1.32
  +++ protocol.c	2001/07/24 22:55:29	1.33
  @@ -154,7 +154,7 @@
   {
       r->clength = clength;
       apr_table_setn(r->headers_out, "Content-Length",
  -                   apr_psprintf(r->pool, "%" APR_OFF_T_FMT, clength));
  +		   apr_off_t_toa(r->pool, clength));
   }
   
   /*
  
  
  

Mime
View raw message