From 4bf361a0e96f63e090833f7c390b9ecd5fb9a436 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Tue, 15 Jul 2003 22:29:38 +0000 Subject: [PATCH] optimization: rewrite reduce_uri function: 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 | 61 +++++++++++++---------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 22c81ade92..3202902737 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -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; -- 2.50.1