httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/filters mod_include.c
Date Mon, 25 Aug 2003 16:05:13 GMT
nd          2003/08/25 09:05:13

  Modified:    modules/filters mod_include.c
  Log:
  short circuit && and || evaluation. For backwards compat this is only
  possible if there's no regex on the short circuited side (since it fills
  in the backref data). The user may optimize this by putting the regex
  onto the left side of the operator.
  
  Revision  Changes    Path
  1.266     +41 -23    httpd-2.0/modules/filters/mod_include.c
  
  Index: mod_include.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/filters/mod_include.c,v
  retrieving revision 1.265
  retrieving revision 1.266
  diff -u -r1.265 -r1.266
  --- mod_include.c	25 Aug 2003 15:36:51 -0000	1.265
  +++ mod_include.c	25 Aug 2003 16:05:13 -0000	1.266
  @@ -1123,7 +1123,8 @@
       const char* buffer;
       const char *parse = expr;
       int retval = 0, was_unmatched = 0;
  -    
  +    unsigned regex = 0;
  +
       *was_error = 0;
   
       if (!parse) {
  @@ -1196,6 +1197,7 @@
               case TOKEN_NOT:
                   new->parent = current;
                   current = current->right = new;
  +                ++regex;
                   break;
   
               default:
  @@ -1438,39 +1440,54 @@
                       continue;
                   }
               }
  -            if (!current->right->done) {
  -                switch (current->right->token.type) {
  -                case TOKEN_STRING:
  -                    buffer = ap_ssi_parse_string(ctx,
  -                                                 current->right->token.value,
  -                                                 NULL, 0, SSI_EXPAND_DROP_NAME);
   
  -                    current->right->token.value = buffer;
  -                    current->right->value = !!*current->right->token.value;
  -                    current->right->done = 1;
  -                    break;
  +            /* short circuit evaluation */
  +            if (!current->right->done && !regex &&
  +                ((current->token.type == TOKEN_AND && !current->left->value)
||
  +                (current->token.type == TOKEN_OR && current->left->value)))
{
  +                DEBUG_PRINTF((ctx, "     Left: %c\n", current->left->value
  +                                                                  ? '1' : '0'));
  +                DEBUG_PRINTF((ctx, "     Right: short circuited\n"));
   
  -                default:
  -                    current = current->right;
  -                    continue;
  -                }
  +                current->value = current->left->value;
               }
  +            else {
  +                if (!current->right->done) {
  +                    switch (current->right->token.type) {
  +                    case TOKEN_STRING:
  +                        buffer = ap_ssi_parse_string(ctx,
  +                                                     current->right->token.value,
  +                                                     NULL, 0,
  +                                                     SSI_EXPAND_DROP_NAME);
  +
  +                        current->right->token.value = buffer;
  +                        current->right->value = !!*current->right->token.value;
  +                        current->right->done = 1;
  +                        break;
  +
  +                    default:
  +                        current = current->right;
  +                        continue;
  +                    }
  +                }
   
  -            DEBUG_PRINTF((ctx, "     Left: %c\n", current->left->value
  +                DEBUG_PRINTF((ctx, "     Left: %c\n", current->left->value
                                                                     ? '1' : '0'));
  -            DEBUG_PRINTF((ctx, "     Right: %c\n", current->right->value
  +                DEBUG_PRINTF((ctx, "     Right: %c\n", current->right->value
                                                                     ? '1' : '0'));
   
  -            if (current->token.type == TOKEN_AND) {
  -                current->value = current->left->value && current->right->value;
  -            }
  -            else {
  -                current->value = current->left->value || current->right->value;
  +                if (current->token.type == TOKEN_AND) {
  +                    current->value = current->left->value &&
  +                                     current->right->value;
  +                }
  +                else {
  +                    current->value = current->left->value ||
  +                                     current->right->value;
  +                }
               }
   
               DEBUG_PRINTF((ctx, "     Returning %c\n", current->value
                                                                     ? '1' : '0'));
  -
               current->done = 1;
               current = current->parent;
               break;
  @@ -1505,6 +1522,7 @@
   
                   current->value = re_check(ctx, current->left->token.value,
                                             current->right->token.value);
  +                --regex;
               }
               else {
                   DEBUG_PRINTF((ctx, "     Compare (%s) with (%s)\n",
  
  
  

Mime
View raw message