summaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorpavel <pavel.rosicky@easy.cz>2019-07-19 14:23:00 (GMT)
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-08-28 02:29:49 (GMT)
commit8e13da1ee83028000e5d7f9f9526379e32765a81 (patch)
tree2ac2cac18839da9817632d3427a1b5f317cc9674 /st.c
parent989e8ad322afdfa3aa06e74b89fc42aef42895d0 (diff)
optimize get_power2 [Feature #15631]
Merged: https://github.com/ruby/ruby/pull/2292
Diffstat (limited to 'st.c')
-rw-r--r--st.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/st.c b/st.c
index 880ab87..618143f 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