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 Mon, 28 Jul 2003 23:06:54 GMT
nd          2003/07/28 16:06:54

  Modified:    modules/mappers mod_rewrite.c
  Log:
  integrate the random functions into the select_random_value_part
  function. This is the only place where they are needed. It is
  not necessary to add extra cycles for function calls here.
  
  Revision  Changes    Path
  1.196     +14 -25    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.195
  retrieving revision 1.196
  diff -u -r1.195 -r1.196
  --- mod_rewrite.c	28 Jul 2003 22:48:51 -0000	1.195
  +++ mod_rewrite.c	28 Jul 2003 23:06:54 -0000	1.196
  @@ -1038,30 +1038,6 @@
       return key;
   }
   
  -static void rewrite_rand_init(void)
  -{
  -    if (!rewrite_rand_init_done) {
  -        srand((unsigned)(getpid()));
  -        rewrite_rand_init_done = 1;
  -    }
  -    return;
  -}
  -
  -static int rewrite_rand(int l, int h)
  -{
  -    /* XXX: In order to be clean, this should be wrapped into a thread mutex,
  -     * shouldn't it? Though it probably doesn't care very much...
  -     */
  -    rewrite_rand_init();
  -
  -    /* Get [0,1) and then scale to the appropriate range. Note that using
  -     * a floating point value ensures that we use all bits of the rand()
  -     * result. Doing an integer modulus would only use the lower-order bits
  -     * which may not be as uniformly random.
  -     */
  -    return (int)(((double)(rand() % RAND_MAX) / RAND_MAX) * (h - l + 1) + l);
  -}
  -
   static char *select_random_value_part(request_rec *r, char *value)
   {
       char *p = value;
  @@ -1074,7 +1050,20 @@
       }
   
       if (n > 1) {
  -        n = rewrite_rand(1, n);
  +        /* initialize random generator
  +         *
  +         * XXX: Probably this should be wrapped into a thread mutex,
  +         * shouldn't it? Is it worth the effort?
  +         */
  +        if (!rewrite_rand_init_done) {
  +            srand((unsigned)(getpid()));
  +            rewrite_rand_init_done = 1;
  +        }
  +
  +        /* select a random subvalue */
  +        n = (int)(((double)(rand() % RAND_MAX) / RAND_MAX) * n + 1);
  +
  +        /* extract it from the whole string */
           while (--n && (value = ap_strchr(value, '|')) != NULL) {
               ++value;
           }
  
  
  

Mime
View raw message