]> granicus.if.org Git - apache/commitdiff
minor optimization: the bracket search functions just search
authorAndré Malo <nd@apache.org>
Tue, 29 Jul 2003 21:37:59 +0000 (21:37 +0000)
committerAndré Malo <nd@apache.org>
Tue, 29 Jul 2003 21:37:59 +0000 (21:37 +0000)
for curly brackets, so there's no need to supply that every
time again.

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

modules/mappers/mod_rewrite.c

index 92c461f0e49fd60cf552332bd4b8f5e5f48f2766..3985c113bbbf54183adeb526a77f5816157fee32 100644 (file)
 #define REWRITE_MAX_PRG_MAP_LINE 2048
 #endif
 
+/* for better readbility */
+#define LEFT_CURLY  '{'
+#define RIGHT_CURLY '}'
+
 /*
  * +-------------------------------------------------------+
  * |                                                       |
@@ -1858,36 +1862,38 @@ static char *lookup_variable(request_rec *r, char *var)
  * Bracketed expression handling
  * s points after the opening bracket
  */
-static char *find_closing_bracket(char *s, int left, int right)
+static char *find_closing_curly(char *s)
 {
-    int depth;
+    unsigned depth;
 
     for (depth = 1; *s; ++s) {
-        if (*s == right && --depth == 0) {
+        if (*s == RIGHT_CURLY && --depth == 0) {
             return s;
         }
-        else if (*s == left) {
+        else if (*s == LEFT_CURLY) {
             ++depth;
         }
     }
+
     return NULL;
 }
 
-static char *find_char_in_brackets(char *s, int c, int left, int right)
+static char *find_char_in_curlies(char *s, int c)
 {
-    int depth;
+    unsigned depth;
 
     for (depth = 1; *s; ++s) {
         if (*s == c && depth == 1) {
             return s;
         }
-        else if (*s == right && --depth == 0) {
+        else if (*s == RIGHT_CURLY && --depth == 0) {
             return NULL;
         }
-        else if (*s == left) {
+        else if (*s == LEFT_CURLY) {
             ++depth;
         }
     }
+
     return NULL;
 }
 
@@ -1952,7 +1958,7 @@ static char *do_expand(request_rec *r, char *input,
         else if (p[1] == '{') {
             char *endp;
 
-            endp = find_closing_bracket(p+2, '{', '}');
+            endp = find_closing_curly(p+2);
             if (!endp) {
                 current->len = 2;
                 current->string = p;
@@ -1988,7 +1994,7 @@ static char *do_expand(request_rec *r, char *input,
                  * driven by the syntax of the nested curly brackets.
                  */
 
-                key = find_char_in_brackets(p+2, ':', '{', '}');
+                key = find_char_in_curlies(p+2, ':');
                 if (!key) {
                     current->len = 2;
                     current->string = p;
@@ -2001,7 +2007,7 @@ static char *do_expand(request_rec *r, char *input,
                     map = apr_pstrmemdup(r->pool, p+2, endp-p-2);
                     key = map + (key-p-2);
                     *key++ = '\0';
-                    dflt = find_char_in_brackets(key, '|', '{', '}');
+                    dflt = find_char_in_curlies(key, '|');
                     if (dflt) {
                         *dflt++ = '\0';
                     }