#include "parser/gramparse.h"
#include "parser/parser.h" /* only needed for GUC variables */
#include "parser/scansup.h"
+#include "port/pg_bitutils.h"
#include "mb/pg_wchar.h"
}
/* enlarge buffer if needed */
if ((yyextra->literallen + yleng) >= yyextra->literalalloc)
{
- do
- {
- yyextra->literalalloc *= 2;
- } while ((yyextra->literallen + yleng) >= yyextra->literalalloc);
+ yyextra->literalalloc = pg_nextpower2_32(yyextra->literallen + yleng + 1);
yyextra->literalbuf = (char *) repalloc(yyextra->literalbuf,
yyextra->literalalloc);
}
#include "miscadmin.h"
#include "pgstat.h"
+#include "port/pg_bitutils.h"
#include "postmaster/bgworker.h"
#include "storage/procsignal.h"
#include "storage/shm_mq.h"
*/
if (mqh->mqh_buflen < nbytes)
{
- Size newbuflen = Max(mqh->mqh_buflen, MQH_INITIAL_BUFSIZE);
+ Size newbuflen;
/*
- * Double the buffer size until the payload fits, but limit to
- * MaxAllocSize.
+ * Increase size to the next power of 2 that's >= nbytes, but
+ * limit to MaxAllocSize.
*/
- while (newbuflen < nbytes)
- newbuflen *= 2;
+#if SIZEOF_SIZE_T == 4
+ newbuflen = pg_nextpower2_32(nbytes);
+#else
+ newbuflen = pg_nextpower2_64(nbytes);
+#endif
newbuflen = Min(newbuflen, MaxAllocSize);
if (mqh->mqh_buffer != NULL)
#include "miscadmin.h"
#include "pg_trace.h"
#include "pgstat.h"
+#include "port/pg_bitutils.h"
#include "postmaster/postmaster.h"
#include "replication/slot.h"
#include "storage/ipc.h"
{
int newalloc;
- newalloc = Max(LWLockTrancheNamesAllocated, 8);
- while (newalloc <= tranche_id)
- newalloc *= 2;
+ newalloc = pg_nextpower2_32(Max(8, tranche_id + 1));
if (LWLockTrancheNames == NULL)
LWLockTrancheNames = (const char **)
if (NamedLWLockTrancheRequests >= NamedLWLockTrancheRequestsAllocated)
{
- int i = NamedLWLockTrancheRequestsAllocated;
-
- while (i <= NamedLWLockTrancheRequests)
- i *= 2;
+ int i = pg_nextpower2_32(NamedLWLockTrancheRequests + 1);
NamedLWLockTrancheRequestArray = (NamedLWLockTrancheRequest *)
repalloc(NamedLWLockTrancheRequestArray,
else if (*Conf->AffixData[a2] == '\0')
return a1;
- while (Conf->nAffixData + 1 >= Conf->lenAffixData)
+ /* Double the size of AffixData if there's not enough space */
+ if (Conf->nAffixData + 1 >= Conf->lenAffixData)
{
Conf->lenAffixData *= 2;
Conf->AffixData = (char **) repalloc(Conf->AffixData,
static void
hladdword(HeadlineParsedText *prs, char *buf, int buflen, int type)
{
- while (prs->curwords >= prs->lenwords)
+ if (prs->curwords >= prs->lenwords)
{
prs->lenwords *= 2;
prs->words = (HeadlineWordEntry *) repalloc((void *) prs->words, prs->lenwords * sizeof(HeadlineWordEntry));
#include "catalog/catalog.h"
#include "catalog/pg_constraint.h"
#include "miscadmin.h"
+#include "port/pg_bitutils.h"
#include "storage/sinval.h"
#include "storage/smgr.h"
#include "utils/catcache.h"
if ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
{
- while ((numSharedInvalidMessagesArray + n) > maxSharedInvalidMessagesArray)
- maxSharedInvalidMessagesArray *= 2;
+ maxSharedInvalidMessagesArray = pg_nextpower2_32(numSharedInvalidMessagesArray + n);
SharedInvalidMessagesArray = repalloc(SharedInvalidMessagesArray,
maxSharedInvalidMessagesArray
#include "executor/executor.h"
#include "lib/dshash.h"
#include "optimizer/optimizer.h"
+#include "port/pg_bitutils.h"
#include "storage/lwlock.h"
#include "utils/builtins.h"
#include "utils/catcache.h"
if (typmod >= RecordCacheArrayLen)
{
- int32 newlen = RecordCacheArrayLen * 2;
-
- while (typmod >= newlen)
- newlen *= 2;
+ int32 newlen = pg_nextpower2_32(typmod + 1);
RecordCacheArray = (TupleDesc *) repalloc(RecordCacheArray,
newlen * sizeof(TupleDesc));