Minor code improvements of dict.c #834

Closed
wants to merge 3 commits into from

1 participant

@huangz1990

All testes passed.

@huangz1990

About the huangz1990/redis-1@8b42017 :

If x >= y , it must be x / y >= 1 , so the expression d->ht[0].used >= d->ht[0].size can replace by d->ht[0].used / d->ht[0].size >= 1, then we get

if (d->ht[0].used / d->ht[0].size >= 1 && 
    (dict_can_resize || d->ht[0].used / d->ht[0].size > dict_force_resize_ratio))

because d->ht[0].used / d->ht[0].size is calculate two times, so we'd better use a variable to store it, then we get:

unsigned long ratio = d->ht[0].used / d->ht[0].size;
if (ratio >= 1 && (dict_can_resize || ratio > dict_force_resize_ratio)

and the if condition can transform to :

if ((ratio >= 1 && dict_can_resize) || (ratio >= 1 && ratio > dict_force_resize_ratio))

because dict_force_resize_ratio must be greater or equal to 1 (otherwise, it's meaningless), so if ratio > dict_force_resize_ratio is true, the ratio >= 1 must be true, then the condition can transform to:

if ((ratio >= 1 && dict_can_resize) || (ratio > dict_force_resize_ratio))

that's it.

@huangz1990 huangz1990 closed this Mar 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment