fielding    97/02/16 21:22:58

  Modified:    src       CHANGES mod_include.c
  Log:
  Added double-buffering to mod_include to improve performance on
  server-side includes.
  
  Submitted by: Marc Slemko
  Reviewed by: Roy Fielding, Brian Behlendorf, Dean Gaudet
  
  Revision  Changes    Path
  1.166     +3 -0      apache/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /export/home/cvs/apache/src/CHANGES,v
  retrieving revision 1.165
  retrieving revision 1.166
  diff -C3 -r1.165 -r1.166
  *** CHANGES   1997/02/17 04:52:38     1.165
  --- CHANGES   1997/02/17 05:22:56     1.166
  ***************
  *** 33,38 ****
  --- 33,41 ----
         auto initializers, multiple is_matchexp calls on a static string,
         and excessive merging of response_code_strings. [Dean Gaudet]
    
  +   *) Added double-buffering to mod_include to improve performance on
  +      server-side includes. [Marc Slemko]
  + 
      *) Several fixes for suexec wrapper. [Randy Terbush]
         - Make wrapper work for files on NFS filesystem.
         - Fix portability problem of MAXPATHLEN.
  
  
  
  1.22      +67 -14    apache/src/mod_include.c
  
  Index: mod_include.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/mod_include.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -C3 -r1.21 -r1.22
  *** mod_include.c     1997/01/20 04:28:13     1.21
  --- mod_include.c     1997/02/17 05:22:57     1.22
  ***************
  *** 113,156 ****
        }
    }
    
  ! #define GET_CHAR(f,c,r,p) \
     { \
       int i = getc(f); \
  !    if(feof(f) || ferror(f) || (i == -1)) { \
  !         pfclose(p,f); \
  !         return r; \
       } \
       c = (char)i; \
     }
    
  - /* --------------------------- Parser functions --------------------------- 
*/
  - 
  - /* 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 printing) {
        int x,l=strlen(str),p;
        char c;
    
        p=0;
        while(1) {
  !         GET_CHAR(in,c,1,r->pool);
            if(c == str[p]) {
  !             if((++p) == l)
                    return 0;
            }
            else {
                if (printing) {
                    for(x=0;x<p;x++) {
  !                     rputc(str[x],r);
                    }
  !                 rputc(c,r);
                }
                p=0;
            }
        }
    }
    
    /*
     * decodes a string containing html entities or numeric character 
references.
  --- 113,209 ----
        }
    }
    
  ! 
  ! 
  ! /* --------------------------- Parser functions --------------------------- 
*/
  ! 
  ! #define OUTBUFSIZE 4096
  ! /* PUT_CHAR and FLUSH_BUF currently only work within the scope of 
  !  * find_string(); they are hacks to avoid calling rputc for each and
  !  * every character output.  A common set of buffering calls for this 
  !  * type of output SHOULD be implemented.
  !  */
  ! #define PUT_CHAR(c,r) \
  !  { \
  !    outbuf[outind++] = c; \
  !    if (outind == OUTBUFSIZE) { FLUSH_BUF(r) }; \
  !  } 
  ! 
  ! /* there SHOULD be some error checking on the return value of
  !  * rwrite, however it is unclear what the API for rwrite returning
  !  * errors is and little can really be done to help the error in 
  !  * any case.
  !  */
  ! #define FLUSH_BUF(r) \
  !  { \
  !    rwrite(outbuf, outind, r); \
  !    outind = 0; \
  !  }
  ! 
  ! /*
  !  * f: file handle being read from
  !  * c: character to read into
  !  * ret: return value to use if input fails
  !  * r: current request_rec
  !  *
  !  * This macro is redefined after find_string() for historical reasons
  !  * to avoid too many code changes.  This is one of the many things
  !  * that should be fixed.
  !  */
  ! #define GET_CHAR(f,c,ret,r) \
     { \
       int i = getc(f); \
  !    if(i == EOF) { /* either EOF or error -- needs error handling if latter 
*/ \
  !        if (ferror(f)) \
  !        fprintf(stderr, "encountered error in GET_CHAR macro, 
mod_include.\n"); \
  !        FLUSH_BUF(r); \
  !        pfclose(r->pool,f); \
  !        return ret; \
       } \
       c = (char)i; \
     }
    
    int find_string(FILE *in,char *str, request_rec *r, int printing) {
        int x,l=strlen(str),p;
  +     char outbuf[OUTBUFSIZE];
  +     int outind = 0;
        char c;
    
        p=0;
        while(1) {
  !         GET_CHAR(in,c,1,r);
            if(c == str[p]) {
  !             if((++p) == l) {
  !             FLUSH_BUF(r);
                    return 0;
  +         }
            }
            else {
                if (printing) {
                    for(x=0;x<p;x++) {
  !                     PUT_CHAR(str[x],r);
                    }
  !                 PUT_CHAR(c,r);
                }
                p=0;
            }
        }
    }
  + 
  + #undef FLUSH_BUF
  + #undef PUT_CHAR
  + #undef GET_CHAR
  + #define GET_CHAR(f,c,r,p) \
  +  { \
  +    int i = getc(f); \
  +    if(i == EOF) { /* either EOF or error -- needs error handling if latter 
*/ \
  +        if (ferror(f)) \
  +        fprintf(stderr, "encountered error in GET_CHAR macro, 
mod_include.\n"); \
  +        pfclose(p,f); \
  +        return r; \
  +    } \
  +    c = (char)i; \
  +  }
    
    /*
     * decodes a string containing html entities or numeric character 
references.
  
  
  

Reply via email to