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/mappers mod_rewrite.c
Date Sun, 27 Jul 2003 19:18:27 GMT
nd          2003/07/27 12:18:27

  Modified:    modules/mappers mod_rewrite.c
  Log:
  cleanup the select_random_value_part function.
  improve efficiency and readabilty.
  
  Revision  Changes    Path
  1.186     +18 -26    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.185
  retrieving revision 1.186
  diff -u -r1.185 -r1.186
  --- mod_rewrite.c	27 Jul 2003 14:40:52 -0000	1.185
  +++ mod_rewrite.c	27 Jul 2003 19:18:27 -0000	1.186
  @@ -1226,38 +1226,30 @@
   
   static char *select_random_value_part(request_rec *r, char *value)
   {
  -    char *buf;
  -    int n, i, k;
  +    char *p = value;
  +    unsigned n = 1;
   
  -    /*  count number of distinct values  */
  -    for (n = 1, i = 0; value[i] != '\0'; i++) {
  -        if (value[i] == '|') {
  -            n++;
  -        }
  -    }
  -
  -    /*  when only one value we have no option to choose  */
  -    if (n == 1) {
  -        return value;
  +    /* count number of distinct values */
  +    while ((p = ap_strchr(p, '|')) != NULL) {
  +        ++n;
  +        ++p;
       }
   
  -    /*  else randomly select one  */
  -    k = rewrite_rand(1, n);
  -
  -    /*  and grep it out  */
  -    for (n = 1, i = 0; value[i] != '\0'; i++) {
  -        if (n == k) {
  -            break;
  +    if (n > 1) {
  +        n = rewrite_rand(1, n);
  +        while (--n && (value = ap_strchr(value, '|')) != NULL) {
  +            ++value;
           }
  -        if (value[i] == '|') {
  -            n++;
  +
  +        if (value) { /* should not be NULL, but ... */
  +            p = ap_strchr(value, '|');
  +            if (p) {
  +                *p = '\0';
  +            }
           }
       }
  -    buf = apr_pstrdup(r->pool, &value[i]);
  -    for (i = 0; buf[i] != '\0' && buf[i] != '|'; i++)
  -        ;
  -    buf[i] = '\0';
  -    return buf;
  +
  +    return value;
   }
   
   /* child process code */
  
  
  

Mime
View raw message