diff --git a/src/cairo-skiplist-private.h b/src/cairo-skiplist-private.h index cf1a99bad..3a948afce 100644 --- a/src/cairo-skiplist-private.h +++ b/src/cairo-skiplist-private.h @@ -32,6 +32,9 @@ * http://citeseer.ist.psu.edu/pugh90skip.html */ +/* Note that random_level() called from alloc_node_for_level() depends on + * this being not more than 16. + */ #define MAX_LEVEL 15 /* Returns the index of the free-list to use for a node at level 'level' */ diff --git a/src/cairo-skiplist.c b/src/cairo-skiplist.c index 52d846527..2d2fbb002 100644 --- a/src/cairo-skiplist.c +++ b/src/cairo-skiplist.c @@ -269,9 +269,12 @@ _cairo_skip_list_fini (cairo_skip_list_t *list) static int random_level (void) { - /* tricky bit -- each bit is '1' 75% of the time */ - long int bits = lfsr_random() | lfsr_random(); int level = 0; + /* tricky bit -- each bit is '1' 75% of the time. + * This works because we only use the lower MAX_LEVEL + * bits, and MAX_LEVEL < 16 */ + long int bits = lfsr_random(); + bits |= bits >> 16; while (++level < MAX_LEVEL) {