From 8e13da1ee83028000e5d7f9f9526379e32765a81 Mon Sep 17 00:00:00 2001 From: pavel Date: Fri, 19 Jul 2019 16:23:00 +0200 Subject: optimize get_power2 [Feature #15631] Merged: https://github.com/ruby/ruby/pull/2292 --- st.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'st.c') diff --git a/st.c b/st.c index 880ab8769b..618143f29d 100644 --- a/st.c +++ b/st.c @@ -345,10 +345,7 @@ do_hash(st_data_t key, st_table *tab) static int get_power2(st_index_t size) { - unsigned int n; - - for (n = 0; size != 0; n++) - size >>= 1; + unsigned int n = ST_INDEX_BITS - nlz_intptr(size); if (n <= MAX_POWER2) return n < MINIMAL_POWER2 ? MINIMAL_POWER2 : n; #ifndef NOT_RUBY -- cgit v1.2.3