1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-28 11:44:57 +03:00

backend/nodes cleanup: Move loop variables definitions into for statement

Author: Chao Li (Evan) <lic@highgo.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEoWx2nP12qwAaiJutbn1Kw50atN6FbMJNQ4bh4%2BfP_Ay_u7Eg%40mail.gmail.com
This commit is contained in:
Peter Eisentraut
2025-11-25 15:38:23 +01:00
parent 3df4df53b0
commit 2256af4ba2
6 changed files with 20 additions and 35 deletions

View File

@@ -538,7 +538,6 @@ bms_is_member(int x, const Bitmapset *a)
int
bms_member_index(Bitmapset *a, int x)
{
int i;
int bitnum;
int wordnum;
int result = 0;
@@ -554,7 +553,7 @@ bms_member_index(Bitmapset *a, int x)
bitnum = BITNUM(x);
/* count bits in preceding words */
for (i = 0; i < wordnum; i++)
for (int i = 0; i < wordnum; i++)
{
bitmapword w = a->words[i];
@@ -1306,7 +1305,6 @@ int
bms_next_member(const Bitmapset *a, int prevbit)
{
int nwords;
int wordnum;
bitmapword mask;
Assert(bms_is_valid_set(a));
@@ -1316,7 +1314,7 @@ bms_next_member(const Bitmapset *a, int prevbit)
nwords = a->nwords;
prevbit++;
mask = (~(bitmapword) 0) << BITNUM(prevbit);
for (wordnum = WORDNUM(prevbit); wordnum < nwords; wordnum++)
for (int wordnum = WORDNUM(prevbit); wordnum < nwords; wordnum++)
{
bitmapword w = a->words[wordnum];
@@ -1366,7 +1364,6 @@ bms_next_member(const Bitmapset *a, int prevbit)
int
bms_prev_member(const Bitmapset *a, int prevbit)
{
int wordnum;
int ushiftbits;
bitmapword mask;
@@ -1391,7 +1388,7 @@ bms_prev_member(const Bitmapset *a, int prevbit)
ushiftbits = BITS_PER_BITMAPWORD - (BITNUM(prevbit) + 1);
mask = (~(bitmapword) 0) >> ushiftbits;
for (wordnum = WORDNUM(prevbit); wordnum >= 0; wordnum--)
for (int wordnum = WORDNUM(prevbit); wordnum >= 0; wordnum--)
{
bitmapword w = a->words[wordnum];

View File

@@ -4826,9 +4826,7 @@ planstate_walk_members(PlanState **planstates, int nplans,
planstate_tree_walker_callback walker,
void *context)
{
int j;
for (j = 0; j < nplans; j++)
for (int j = 0; j < nplans; j++)
{
if (PSWALK(planstates[j]))
return true;

View File

@@ -346,8 +346,7 @@ outBitmapset(StringInfo str, const Bitmapset *bms)
void
outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
{
Size length,
i;
Size length;
char *s;
length = datumGetSize(value, typbyval, typlen);
@@ -356,7 +355,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
{
s = (char *) (&value);
appendStringInfo(str, "%u [ ", (unsigned int) length);
for (i = 0; i < (Size) sizeof(Datum); i++)
for (Size i = 0; i < (Size) sizeof(Datum); i++)
appendStringInfo(str, "%d ", (int) (s[i]));
appendStringInfoChar(str, ']');
}
@@ -368,7 +367,7 @@ outDatum(StringInfo str, Datum value, int typlen, bool typbyval)
else
{
appendStringInfo(str, "%u [ ", (unsigned int) length);
for (i = 0; i < length; i++)
for (Size i = 0; i < length; i++)
appendStringInfo(str, "%d ", (int) (s[i]));
appendStringInfoChar(str, ']');
}
@@ -434,8 +433,6 @@ _outBoolExpr(StringInfo str, const BoolExpr *node)
static void
_outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
{
int i;
WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
WRITE_UINT_FIELD(con_relid);
@@ -450,10 +447,10 @@ _outForeignKeyOptInfo(StringInfo str, const ForeignKeyOptInfo *node)
WRITE_INT_FIELD(nmatched_ri);
/* for compactness, just print the number of matches per column: */
appendStringInfoString(str, " :eclass");
for (i = 0; i < node->nkeys; i++)
for (int i = 0; i < node->nkeys; i++)
appendStringInfo(str, " %d", (node->eclass[i] != NULL));
appendStringInfoString(str, " :rinfos");
for (i = 0; i < node->nkeys; i++)
for (int i = 0; i < node->nkeys; i++)
appendStringInfo(str, " %d", list_length(node->rinfos[i]));
}

View File

@@ -166,13 +166,12 @@ paramlist_param_ref(ParseState *pstate, ParamRef *pref)
Size
EstimateParamListSpace(ParamListInfo paramLI)
{
int i;
Size sz = sizeof(int);
if (paramLI == NULL || paramLI->numParams <= 0)
return sz;
for (i = 0; i < paramLI->numParams; i++)
for (int i = 0; i < paramLI->numParams; i++)
{
ParamExternData *prm;
ParamExternData prmdata;
@@ -229,7 +228,6 @@ void
SerializeParamList(ParamListInfo paramLI, char **start_address)
{
int nparams;
int i;
/* Write number of parameters. */
if (paramLI == NULL || paramLI->numParams <= 0)
@@ -240,7 +238,7 @@ SerializeParamList(ParamListInfo paramLI, char **start_address)
*start_address += sizeof(int);
/* Write each parameter in turn. */
for (i = 0; i < nparams; i++)
for (int i = 0; i < nparams; i++)
{
ParamExternData *prm;
ParamExternData prmdata;

View File

@@ -599,8 +599,7 @@ parseNodeString(void)
Datum
readDatum(bool typbyval)
{
Size length,
i;
Size length;
int tokenLength;
const char *token;
Datum res;
@@ -623,7 +622,7 @@ readDatum(bool typbyval)
elog(ERROR, "byval datum but length = %zu", length);
res = (Datum) 0;
s = (char *) (&res);
for (i = 0; i < (Size) sizeof(Datum); i++)
for (Size i = 0; i < (Size) sizeof(Datum); i++)
{
token = pg_strtok(&tokenLength);
s[i] = (char) atoi(token);
@@ -634,7 +633,7 @@ readDatum(bool typbyval)
else
{
s = (char *) palloc(length);
for (i = 0; i < length; i++)
for (Size i = 0; i < length; i++)
{
token = pg_strtok(&tokenLength);
s[i] = (char) atoi(token);

View File

@@ -369,10 +369,9 @@ tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids,
{
BlockNumber currblk = InvalidBlockNumber;
PagetableEntry *page = NULL; /* only valid when currblk is valid */
int i;
Assert(tbm->iterating == TBM_NOT_ITERATING);
for (i = 0; i < ntids; i++)
for (int i = 0; i < ntids; i++)
{
BlockNumber blk = ItemPointerGetBlockNumber(tids + i);
OffsetNumber off = ItemPointerGetOffsetNumber(tids + i);
@@ -471,12 +470,11 @@ static void
tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
{
PagetableEntry *apage;
int wordnum;
if (bpage->ischunk)
{
/* Scan b's chunk, mark each indicated page lossy in a */
for (wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
for (int wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
{
bitmapword w = bpage->words[wordnum];
@@ -511,7 +509,7 @@ tbm_union_page(TIDBitmap *a, const PagetableEntry *bpage)
else
{
/* Both pages are exact, merge at the bit level */
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
apage->words[wordnum] |= bpage->words[wordnum];
apage->recheck |= bpage->recheck;
}
@@ -579,14 +577,13 @@ static bool
tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
{
const PagetableEntry *bpage;
int wordnum;
if (apage->ischunk)
{
/* Scan each bit in chunk, try to clear */
bool candelete = true;
for (wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
for (int wordnum = 0; wordnum < WORDS_PER_CHUNK; wordnum++)
{
bitmapword w = apage->words[wordnum];
@@ -640,7 +637,7 @@ tbm_intersect_page(TIDBitmap *a, PagetableEntry *apage, const TIDBitmap *b)
{
/* Both pages are exact, merge at the bit level */
Assert(!bpage->ischunk);
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
{
apage->words[wordnum] &= bpage->words[wordnum];
if (apage->words[wordnum] != 0)
@@ -904,10 +901,9 @@ tbm_extract_page_tuple(TBMIterateResult *iteritem,
uint32 max_offsets)
{
PagetableEntry *page = iteritem->internal_page;
int wordnum;
int ntuples = 0;
for (wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
for (int wordnum = 0; wordnum < WORDS_PER_PAGE; wordnum++)
{
bitmapword w = page->words[wordnum];