diff --git a/src/dict.c b/src/dict.c index 2e335d63a..e34fa029a 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1426,18 +1426,13 @@ static int _dictExpandIfNeeded(dict *d) return DICT_OK; } -/* TODO: clz optimization */ /* Our hash table capability is a power of two */ static signed char _dictNextExp(unsigned long size) { - unsigned char e = DICT_HT_INITIAL_EXP; - + if (size <= DICT_HT_INITIAL_SIZE) return DICT_HT_INITIAL_EXP; if (size >= LONG_MAX) return (8*sizeof(long)-1); - while(1) { - if (((unsigned long)1<= size) - return e; - e++; - } + + return 8*sizeof(long) - __builtin_clzl(size-1); } /* Finds and returns the position within the dict where the provided key should