1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
David Rowley
2020-04-08 18:29:51 +12:00
parent c0187869a0
commit 02a2e8b442
5 changed files with 16 additions and 38 deletions

View File

@ -25,6 +25,7 @@
#include "catalog/pg_am.h"
#include "commands/vacuum.h"
#include "miscadmin.h"
#include "port/pg_bitutils.h"
#include "postmaster/autovacuum.h"
#include "storage/indexfsm.h"
#include "storage/lmgr.h"
@ -503,10 +504,7 @@ ginHeapTupleFastCollect(GinState *ginstate,
* initially. Make it a power of 2 to avoid wasting memory when
* resizing (since palloc likes powers of 2).
*/
collector->lentuples = 16;
while (collector->lentuples < nentries)
collector->lentuples *= 2;
collector->lentuples = pg_nextpower2_32(Max(16, nentries));
collector->tuples = (IndexTuple *) palloc(sizeof(IndexTuple) * collector->lentuples);
}
else if (collector->lentuples < collector->ntuples + nentries)
@ -516,11 +514,7 @@ ginHeapTupleFastCollect(GinState *ginstate,
* overflow, though we could get to a value that exceeds
* MaxAllocSize/sizeof(IndexTuple), causing an error in repalloc.
*/
do
{
collector->lentuples *= 2;
} while (collector->lentuples < collector->ntuples + nentries);
collector->lentuples = pg_nextpower2_32(collector->ntuples + nentries);
collector->tuples = (IndexTuple *) repalloc(collector->tuples,
sizeof(IndexTuple) * collector->lentuples);
}