]> granicus.if.org Git - apache/commitdiff
optimization: rewrite reduce_uri function:
authorAndré Malo <nd@apache.org>
Tue, 15 Jul 2003 22:29:38 +0000 (22:29 +0000)
committerAndré Malo <nd@apache.org>
Tue, 15 Jul 2003 22:29:38 +0000 (22:29 +0000)
get a rid of static buffers and unnecessary memory operations

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100643 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c

index 22c81ade920293dcb311f69f15d5b65e5ce62c87..3202902737037265e14bda30403af113c5c1aa1e 100644 (file)
@@ -2666,14 +2666,6 @@ static void splitout_queryargs(request_rec *r, int qsappend)
 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 @@ static void reduce_uri(request_rec *r)
         && 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] == '/' ) {
+
+        unsigned short port;
+        char *portp, *host, *url, *scratch;
 
-        olduri = apr_pstrdup(r->pool, r->filename); /* save for logging */
+        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;