summaryrefslogtreecommitdiff
path: root/src/backend/nodes
diff options
context:
space:
mode:
authorDavid Rowley2020-04-08 06:29:51 +0000
committerDavid Rowley2020-04-08 06:29:51 +0000
commit02a2e8b442002a698336954633b0ccc4e30061e6 (patch)
treee232e8a3b0fd259c78dc6162af4a8bd3a26e94ff /src/backend/nodes
parentc0187869a0f6eb05135d388462522a593ced1b88 (diff)
Modify additional power 2 calculations to use new helper functions
2nd pass of modifying various places which obtain the next power of 2 of a number and make them use the new functions added in f0705bb62. In passing, also modify num_combinations(). This can be implemented using simple bitshifting rather than looping. Reviewed-by: John Naylor Discussion: https://postgr.es/m/20200114173553.GE32763%40fetter.org
Diffstat (limited to 'src/backend/nodes')
-rw-r--r--src/backend/nodes/list.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/nodes/list.c b/src/backend/nodes/list.c
index bd0c58cd814..80fa8c84e49 100644
--- a/src/backend/nodes/list.c
+++ b/src/backend/nodes/list.c
@@ -18,6 +18,7 @@
#include "postgres.h"
#include "nodes/pg_list.h"
+#include "port/pg_bitutils.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
@@ -119,9 +120,7 @@ new_list(NodeTag type, int min_size)
* that's more than twice the size of an existing list, so the size limits
* within palloc will ensure that we don't overflow here.
*/
- max_size = 8; /* semi-arbitrary small power of 2 */
- while (max_size < min_size + LIST_HEADER_OVERHEAD)
- max_size *= 2;
+ max_size = pg_nextpower2_32(Max(8, min_size + LIST_HEADER_OVERHEAD));
max_size -= LIST_HEADER_OVERHEAD;
#else
@@ -160,12 +159,12 @@ enlarge_list(List *list, int min_size)
/*
* As above, we prefer power-of-two total allocations; but here we need
- * not account for list header overhead. The existing max length might
- * not be a power of 2, so don't rely on that.
+ * not account for list header overhead.
*/
- new_max_len = 16; /* semi-arbitrary small power of 2 */
- while (new_max_len < min_size)
- new_max_len *= 2;
+
+ /* clamp the minimum value to 16, a semi-arbitrary small power of 2 */
+ new_max_len = pg_nextpower2_32(Max(16, min_size));
+
#else
/* As above, don't allocate anything extra */
new_max_len = min_size;