From 7634e76546f5274219bb2edc9dbeb67b7ba0d62d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Mon, 4 Aug 2003 21:47:08 +0000 Subject: [PATCH] improve expansion performance. If we have only small expansions (like just one variable - often used in map keys or the like), don't stress the pool with allocating memory for the linked result pointer list. This list can be safely stored on the stack. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100901 13f79535-47bb-0310-9956-ffa450edef68 --- modules/mappers/mod_rewrite.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 7ef7e78eb3..98613d8fc4 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -224,6 +224,13 @@ #define LEFT_CURLY '{' #define RIGHT_CURLY '}' +/* + * expansion result items on the stack to save some cycles + * + * (5 == about 2 variables like "foo%{var}bar%{var}baz") + */ +#define SMALL_EXPANSION 5 + /* * check that a subrequest won't cause infinite recursion * @@ -1922,6 +1929,8 @@ static char *do_expand(request_rec *r, char *input, backrefinfo *briRR, backrefinfo *briRC) { result_list *result, *current; + result_list sresult[SMALL_EXPANSION]; + unsigned spc = 0; apr_size_t span, inputlen, outlen; char *p, *c; @@ -1934,7 +1943,7 @@ static char *do_expand(request_rec *r, char *input, } /* well, actually something to do */ - result = current = apr_palloc(r->pool, sizeof(result_list)); + result = current = &(sresult[spc++]); p = input + span; current->next = NULL; @@ -1946,7 +1955,9 @@ static char *do_expand(request_rec *r, char *input, do { /* prepare next entry */ if (current->len) { - current->next = apr_palloc(r->pool, sizeof(result_list)); + current->next = (spc < SMALL_EXPANSION) + ? &(sresult[spc++]) + : apr_palloc(r->pool, sizeof(result_list)); current = current->next; current->next = NULL; current->len = 0; @@ -2074,7 +2085,9 @@ static char *do_expand(request_rec *r, char *input, /* check the remainder */ if (*p && (span = strcspn(p, "\\$%")) > 0) { if (current->len) { - current->next = apr_palloc(r->pool, sizeof(result_list)); + current->next = (spc < SMALL_EXPANSION) + ? &(sresult[spc++]) + : apr_palloc(r->pool, sizeof(result_list)); current = current->next; current->next = NULL; } -- 2.50.1