Re: Remove fls(), use pg_bitutils.h facilities instead? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Remove fls(), use pg_bitutils.h facilities instead?
Date
Msg-id 1596564.1658292774@sss.pgh.pa.us
Whole thread Raw
In response to Remove fls(), use pg_bitutils.h facilities instead?  (Thomas Munro <thomas.munro@gmail.com>)
Responses Re: Remove fls(), use pg_bitutils.h facilities instead?
List pgsql-hackers
Thomas Munro <thomas.munro@gmail.com> writes:
> Back in commit 4f658dc8 we gained src/port/fls.c.  As anticipated by
> its commit message, we later finished up with something better in
> src/include/port/pg_bitutils.h.  fls() ("find last set") is an
> off-by-one cousin of pg_leftmost_one_pos32().  I don't know why ffs()
> ("find first set", the rightmost variant) made it into POSIX while
> fls() did not, other than perhaps its more amusing name.  fls() is
> present on *BSD, Macs and maybe more, but not everywhere, hence the
> configure test.  Let's just do it with pg_bitutils.h instead, and drop
> some cruft?  Open to better ideas on whether we need a new function,

I think we could probably just drop fls() entirely.  It doesn't look
to me like any of the existing callers expect a zero argument, so they
could be converted to use pg_leftmost_one_pos32() pretty trivially.
I don't see that fls() is buying us anything that is worth requiring
readers to know yet another nonstandard function.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Junwang Zhao
Date:
Subject: Re: Memory leak fix in psql
Next
From: Fujii Masao
Date:
Subject: Re: Backup command and functions can cause assertion failure and segmentation fault