httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Tue, 15 Jul 2003 22:29:39 GMT
nd          2003/07/15 15:29:39

  Modified:    modules/mappers mod_rewrite.c
  Log:
  optimization: rewrite reduce_uri function:
  get a rid of static buffers and unnecessary memory operations
  
  Revision  Changes    Path
  1.159     +23 -38    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.158
  retrieving revision 1.159
  diff -u -r1.158 -r1.159
  --- mod_rewrite.c	15 Jul 2003 20:38:04 -0000	1.158
  +++ mod_rewrite.c	15 Jul 2003 22:29:38 -0000	1.159
  @@ -2666,14 +2666,6 @@
   static void reduce_uri(request_rec *r)
   {
       char *cp;
  -    unsigned short port;
  -    char *portp;
  -    char *hostp;
  -    char *url;
  -    char c;
  -    char host[LONG_STRING_LEN];
  -    char buf[MAX_STRING_LEN];
  -    char *olduri;
       apr_size_t l;
   
       cp = (char *)ap_http_method(r);
  @@ -2682,55 +2674,48 @@
           && strncasecmp(r->filename, cp, l) == 0
           && r->filename[l]   == ':'
           && r->filename[l+1] == '/'
  -        && r->filename[l+2] == '/'             ) {
  -        /* there was really a rewrite to a remote path */
  +        && r->filename[l+2] == '/' ) {
   
  -        olduri = apr_pstrdup(r->pool, r->filename); /* save for logging */
  +        unsigned short port;
  +        char *portp, *host, *url, *scratch;
  +
  +        scratch = apr_pstrdup(r->pool, r->filename); /* our scratchpad */
   
           /* cut the hostname and port out of the URI */
  -        apr_cpystrn(buf, r->filename+(l+3), sizeof(buf));
  -        hostp = buf;
  -        for (cp = hostp; *cp != '\0' && *cp != '/' && *cp != ':'; cp++)
  -            ;
  -        if (*cp == ':') {
  -            /* set host */
  +        cp = host = scratch + l + 3;    /* 3 == strlen("://") */
  +        while (*cp && *cp != '/' && *cp != ':') {
  +            ++cp;
  +        }
  +
  +        if (*cp == ':') {      /* additional port given */
               *cp++ = '\0';
  -            apr_cpystrn(host, hostp, sizeof(host));
  -            /* set port */
               portp = cp;
  -            for (; *cp != '\0' && *cp != '/'; cp++)
  -                ;
  -            c = *cp;
  +            while (*cp && *cp != '/') {
  +                ++cp;
  +            }
               *cp = '\0';
  +
               port = atoi(portp);
  -            *cp = c;
  -            /* set remaining url */
  -            url = cp;
  +            url = r->filename + (cp - scratch);
  +            if (!*url) {
  +                url = "/";
  +            }
           }
  -        else if (*cp == '/') {
  -            /* set host */
  +        else if (*cp == '/') { /* default port */
               *cp = '\0';
  -            apr_cpystrn(host, hostp, sizeof(host));
  -            *cp = '/';
  -            /* set port */
  +
               port = ap_default_port(r);
  -            /* set remaining url */
  -            url = cp;
  +            url = r->filename + (cp - scratch);
           }
           else {
  -            /* set host */
  -            apr_cpystrn(host, hostp, sizeof(host));
  -            /* set port */
               port = ap_default_port(r);
  -            /* set remaining url */
               url = "/";
           }
   
           /* now check whether we could reduce it to a local path... */
           if (ap_matches_request_vhost(r, host, port)) {
  -            /* this is our host, so only the URL remains */
  +            rewritelog(r, 3, "reduce %s -> %s", r->filename, url);
               r->filename = apr_pstrdup(r->pool, url);
  -            rewritelog(r, 3, "reduce %s -> %s", olduri, r->filename);
           }
       }
       return;
  
  
  

Mime
View raw message