diff --git a/ChangeLog b/ChangeLog index 9dffbed6f4..21d35117d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Oct 3 06:06:28 2014 Eric Wong + + * st.c (next_pow2): new function (from old bignum.c) + (new_size): use next_pow2 function + Fri Oct 3 05:58:58 2014 Eric Wong * vm_trace.c (rb_tp_t): pack 56 => 48 bytes on 64-bit diff --git a/st.c b/st.c index fa3fa3f037..ac58e4d44b 100644 --- a/st.c +++ b/st.c @@ -140,14 +140,31 @@ remove_safe_packed_entry(st_table *table, st_index_t i, st_data_t never) PHASH_SET(table, i, 0); } +static st_index_t +next_pow2(st_index_t x) +{ + x |= x >> 1; + x |= x >> 2; + x |= x >> 4; + x |= x >> 8; + x |= x >> 16; +#if SIZEOF_ST_INDEX_T == 8 + x |= x >> 32; +#endif + return x + 1; +} + static st_index_t new_size(st_index_t size) { - st_index_t i; + st_index_t n; - for (i=3; i<31; i++) { - if ((st_index_t)(1< size) return 1< size) + return n; #ifndef NOT_RUBY rb_raise(rb_eRuntimeError, "st_table too big"); #endif