Confusing comment in tidbitmap.c

Started by David Rowleyover 11 years ago2 messageshackers
Jump to latest
#1David Rowley
dgrowleyml@gmail.com

The following comment above #define PAGES_PER_CHUNK in tibbitmap.c appears
to be incorrect:

"But we
* also want PAGES_PER_CHUNK to be a power of 2 to avoid expensive integer
* remainder operations. So, define it like this:"

I don't quite follow this as it does nothing of the kind.
Check tbm_page_is_lossy() where we do: bitno = pageno % PAGES_PER_CHUNK;

Or am I missing something about the compiler optimizing that to: bitno =
pageno & 255; ?

Regards

David Rowley

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: David Rowley (#1)
Re: Confusing comment in tidbitmap.c

David Rowley <dgrowleyml@gmail.com> writes:

The following comment above #define PAGES_PER_CHUNK in tibbitmap.c appears
to be incorrect:

"But we
* also want PAGES_PER_CHUNK to be a power of 2 to avoid expensive integer
* remainder operations. So, define it like this:"

I don't quite follow this as it does nothing of the kind.
Check tbm_page_is_lossy() where we do: bitno = pageno % PAGES_PER_CHUNK;

Or am I missing something about the compiler optimizing that to: bitno =
pageno & 255; ?

Exactly. Any C compiler ever written will do that.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers