]> granicus.if.org Git - apache/commitdiff
improve expansion performance.
authorAndré Malo <nd@apache.org>
Mon, 4 Aug 2003 21:47:08 +0000 (21:47 +0000)
committerAndré Malo <nd@apache.org>
Mon, 4 Aug 2003 21:47:08 +0000 (21:47 +0000)
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

index 7ef7e78eb3e16fe0ce778f03207a7aac34f8f7c8..98613d8fc4bc172fd466923cfb139aa0d612ccc3 100644 (file)
 #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;
             }