Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex

Поиск
Список
Период
Сортировка
От Atsushi Ogawa
Тема Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
Дата
Msg-id 4A27C837.4060608@hi-ho.ne.jp
обсуждение исходный текст
Ответ на [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex  (Jeremy Kerr <jk@ozlabs.org>)
Ответы Re: [RFC,PATCH] Avoid manual shift-and-test logic in AllocSetFreeIndex
Список pgsql-hackers
> +/*
> + * fls: find last set bit.
> + *
> + * Returns the 1-based index of the most-significant bit in x. The MSB
> + * is bit number 32, the LSB is bit number 1. If x is zero, the result is
> + * undefined.
> + */
> +static inline int
> +fls(unsigned int x)
...
> +        idx = fls((size - 1) >> ALLOC_MINBITS);

If size <= 8, fls((size - 1) >> ALLOC_MINBITS) is fls(0).
The result of fls(0) is undefined.

I think we have to never call fls(0) from AllocSetFreeIndex().
My proposal code:
    if (size > (1 << ALLOC_MINBITS))    {        idx = fls((size - 1) >> ALLOC_MINBITS);        Assert(idx <
ALLOCSET_NUM_FREELISTS);   }
 

Best regards,

---
Atsushi Ogawa


В списке pgsql-hackers по дате отправления: