From 02a2e8b442002a698336954633b0ccc4e30061e6 Mon Sep 17 00:00:00 2001 From: David Rowley Date: Wed, 8 Apr 2020 18:29:51 +1200 Subject: 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 --- src/backend/utils/adt/arrayfuncs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/backend/utils/adt/arrayfuncs.c') diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 7a4a5aaa86d..11987c8f3ba 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -24,6 +24,7 @@ #include "nodes/nodeFuncs.h" #include "nodes/supportnodes.h" #include "optimizer/optimizer.h" +#include "port/pg_bitutils.h" #include "utils/array.h" #include "utils/arrayaccess.h" #include "utils/builtins.h" @@ -5313,9 +5314,7 @@ accumArrayResultArr(ArrayBuildStateArr *astate, memcpy(&astate->lbs[1], lbs, ndims * sizeof(int)); /* Allocate at least enough data space for this item */ - astate->abytes = 1024; - while (astate->abytes <= ndatabytes) - astate->abytes *= 2; + astate->abytes = pg_nextpower2_32(Max(1024, ndatabytes + 1)); astate->data = (char *) palloc(astate->abytes); } else @@ -5362,9 +5361,7 @@ accumArrayResultArr(ArrayBuildStateArr *astate, * First input with nulls; we must retrospectively handle any * previous inputs by marking all their items non-null. */ - astate->aitems = 256; - while (astate->aitems <= newnitems) - astate->aitems *= 2; + astate->aitems = pg_nextpower2_32(Max(256, newnitems + 1)); astate->nullbitmap = (bits8 *) palloc((astate->aitems + 7) / 8); array_bitmap_copy(astate->nullbitmap, 0, NULL, 0, -- cgit v1.2.3