summaryrefslogtreecommitdiff
path: root/src/backend/utils/hash
diff options
context:
space:
mode:
authorDavid Rowley2020-04-08 04:55:03 +0000
committerDavid Rowley2020-04-08 04:55:03 +0000
commitd025cf88ba5a64487ee4a17ef23e8f55b1536606 (patch)
tree02934d8c0207e57dbf88594d43caaa524d80dd1b /src/backend/utils/hash
parent50a38f65177ea7858bc97f71ba0757ba04c1c167 (diff)
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
Diffstat (limited to 'src/backend/utils/hash')
-rw-r--r--src/backend/utils/hash/dynahash.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c
index b5381958e70..5b4b9e487f5 100644
--- a/src/backend/utils/hash/dynahash.c
+++ b/src/backend/utils/hash/dynahash.c
@@ -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 */