httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sam...@atropos.c2.org
Subject [No Subject]
Date Wed, 13 Mar 1996 19:11:16 GMT
From: sameer@c2.org (Sameer Parekh)
Subject: bufferize mod_include
Comments: I needed to remove all the rputc calls in mod_include.c because
	  it had a really bad performance hit on the SSL side.

*** mod_include.c-bak	Tue Mar 12 21:17:58 1996
--- mod_include.c	Wed Mar 13 11:08:55 1996
***************
*** 114,139 ****
  /* Grrrr... rputc makes this slow as all-get-out.  Elsewhere, it doesn't
   * matter much, but this is an inner loop...
   */
  
  int find_string(FILE *in,char *str, request_rec *r) {
      int x,l=strlen(str),p;
      char c;
  
      p=0;
      while(1) {
!         GET_CHAR(in,c,1);
          if(c == str[p]) {
              if((++p) == l)
                  return 0;
!         }
          else {
              if(r) {
                  if(p) {
                      for(x=0;x<p;x++) {
!                         rputc(str[x],r);
                      }
                  }
!                 rputc(c,r);
              }
              p=0;
          }
--- 114,183 ----
  /* Grrrr... rputc makes this slow as all-get-out.  Elsewhere, it doesn't
   * matter much, but this is an inner loop...
   */
+ struct c_buf
+ {
+   char *buffer;
+   request_rec *r;
+   int pos, size;
+ };
  
+ struct c_buf *new_cbuf(request_rec *r, int size)
+ {
+   struct c_buf *buffer = palloc(r->pool, sizeof(struct c_buf));
+ 
+   buffer->buffer = palloc(r->pool, size);
+   buffer->size = size;
+   buffer->r = r;
+   buffer->pos = 0;
+   return(buffer);
+ }
+ 
+ void cbuf_flush(struct c_buf *buffer)
+ {
+   if(buffer == NULL)
+     return;
+   buffer->buffer[buffer->pos] = '\0';
+   rprintf(buffer->r, buffer->buffer);
+   buffer->pos = 0;
+ }
+ 
+ void cbuf_putc(struct c_buf *buffer, char c)
+ {
+   if(buffer->pos >= buffer->size-1)
+     cbuf_flush(buffer);
+   buffer->buffer[buffer->pos] = c;
+   buffer->pos++;
+ }
+   
  int find_string(FILE *in,char *str, request_rec *r) {
      int x,l=strlen(str),p;
      char c;
+     struct c_buf *buf = new_cbuf(r, 1024);
  
      p=0;
      while(1) {
!       c = getc(in);
!       if(feof(in) || ferror(in) || (c == -1))
! 	{
! 	  cbuf_flush(buf);
! 	  fclose(in);
! 	  return(1);
! 	}
          if(c == str[p]) {
              if((++p) == l)
+ 	      {
+ 		cbuf_flush(buf);
                  return 0;
! 	      }
! 	  }
          else {
              if(r) {
                  if(p) {
                      for(x=0;x<p;x++) {
!                         cbuf_putc(buf, str[x]);
                      }
                  }
!                 cbuf_putc(buf, c);
              }
              p=0;
          }

Mime
View raw message