You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2015/04/10 09:51:08 UTC

svn commit: r1672575 - /apr/apr/trunk/tables/apr_skiplist.c

Author: ylavic
Date: Fri Apr 10 07:51:08 2015
New Revision: 1672575

URL: http://svn.apache.org/r1672575
Log:
skiplist: avoid (undefined) unsigned to signed conversion and save cycles in
the hot path get_b_rand().

Modified:
    apr/apr/trunk/tables/apr_skiplist.c

Modified: apr/apr/trunk/tables/apr_skiplist.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/tables/apr_skiplist.c?rev=1672575&r1=1672574&r2=1672575&view=diff
==============================================================================
--- apr/apr/trunk/tables/apr_skiplist.c (original)
+++ apr/apr/trunk/tables/apr_skiplist.c Fri Apr 10 07:51:08 2015
@@ -63,13 +63,12 @@ struct apr_skiplistnode {
 static int get_b_rand(void)
 {
     static int ph = 32;         /* More bits than we will ever use */
-    static apr_uint32_t randseq;
+    static int randseq;
     if (ph > 31) {              /* Num bits in return of rand() */
         ph = 0;
-        randseq = (apr_uint32_t) rand();
+        randseq = rand();
     }
-    ph++;
-    return ((randseq & (1 << (ph - 1))) >> (ph - 1));
+    return randseq & (1 << ph++);
 }
 
 typedef struct {