mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Modify various power 2 calculations to use new helper functions
First pass of modifying various places that obtain the next power of 2 of a number and make them use the new functions added in pg_bitutils.h instead. This also removes the _hash_log2() function. There are no longer any callers in core. Other users can swap their _hash_log2(n) call to make use of pg_ceil_log2_32(n). Author: David Fetter, with some minor adjustments by me Reviewed-by: John Naylor, Jesse Zhang Discussion: https://postgr.es/m/20200114173553.GE32763%40fetter.org
This commit is contained in:
@@ -87,6 +87,7 @@
|
||||
|
||||
#include "access/xact.h"
|
||||
#include "common/hashfn.h"
|
||||
#include "port/pg_bitutils.h"
|
||||
#include "storage/shmem.h"
|
||||
#include "storage/spin.h"
|
||||
#include "utils/dynahash.h"
|
||||
@@ -1718,16 +1719,15 @@ hash_corrupted(HTAB *hashp)
|
||||
int
|
||||
my_log2(long num)
|
||||
{
|
||||
int i;
|
||||
long limit;
|
||||
|
||||
/* guard against too-large input, which would put us into infinite loop */
|
||||
/* guard against too-large input, which would be invalid for pg_ceil_log2_*() */
|
||||
if (num > LONG_MAX / 2)
|
||||
num = LONG_MAX / 2;
|
||||
|
||||
for (i = 0, limit = 1; limit < num; i++, limit <<= 1)
|
||||
;
|
||||
return i;
|
||||
#if SIZEOF_LONG < 8
|
||||
return pg_ceil_log2_32(num);
|
||||
#else
|
||||
return pg_ceil_log2_64(num);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* calculate first power of 2 >= num, bounded to what will fit in a long */
|
||||
|
Reference in New Issue
Block a user