Skip to content

Commit 2b00db4

Browse files
committed
Use l*_node() family of functions where appropriate
Instead of castNode(…, lfoo(…)) Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> Discussion: https://www.postgresql.org/message-id/flat/87eecahraj.fsf@wibble.ilmari.org
1 parent 29abde6 commit 2b00db4

File tree

13 files changed

+33
-33
lines changed

13 files changed

+33
-33
lines changed

src/backend/commands/publicationcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ OpenTableList(List *tables)
514514
*/
515515
foreach(lc, tables)
516516
{
517-
RangeVar *rv = castNode(RangeVar, lfirst(lc));
517+
RangeVar *rv = lfirst_node(RangeVar, lc);
518518
bool recurse = rv->inh;
519519
Relation rel;
520520
Oid myrelid;

src/backend/commands/tablecmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4770,7 +4770,7 @@ ATRewriteCatalogs(List **wqueue, LOCKMODE lockmode,
47704770

47714771
foreach(lcmd, subcmds)
47724772
ATExecCmd(wqueue, tab,
4773-
castNode(AlterTableCmd, lfirst(lcmd)),
4773+
lfirst_node(AlterTableCmd, lcmd),
47744774
lockmode, pass, context);
47754775

47764776
/*
@@ -12842,7 +12842,7 @@ ATPostAlterTypeParse(Oid oldId, Oid oldRelId, Oid refRelId, char *cmd,
1284212842

1284312843
foreach(lcmd, stmt->cmds)
1284412844
{
12845-
AlterTableCmd *cmd = castNode(AlterTableCmd, lfirst(lcmd));
12845+
AlterTableCmd *cmd = lfirst_node(AlterTableCmd, lcmd);
1284612846

1284712847
if (cmd->subtype == AT_AddIndex)
1284812848
{
@@ -16671,7 +16671,7 @@ transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy)
1667116671
/* take care of any partition expressions */
1667216672
foreach(l, partspec->partParams)
1667316673
{
16674-
PartitionElem *pelem = castNode(PartitionElem, lfirst(l));
16674+
PartitionElem *pelem = lfirst_node(PartitionElem, l);
1667516675

1667616676
if (pelem->expr)
1667716677
{
@@ -16708,7 +16708,7 @@ ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNu
1670816708
attn = 0;
1670916709
foreach(lc, partParams)
1671016710
{
16711-
PartitionElem *pelem = castNode(PartitionElem, lfirst(lc));
16711+
PartitionElem *pelem = lfirst_node(PartitionElem, lc);
1671216712
Oid atttype;
1671316713
Oid attcollation;
1671416714

src/backend/executor/execPartition.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, EState *estate,
585585

586586
foreach(ll, wcoList)
587587
{
588-
WithCheckOption *wco = castNode(WithCheckOption, lfirst(ll));
588+
WithCheckOption *wco = lfirst_node(WithCheckOption, ll);
589589
ExprState *wcoExpr = ExecInitQual(castNode(List, wco->qual),
590590
&mtstate->ps);
591591

src/backend/executor/nodeValuesscan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ ExecInitValuesScan(ValuesScan *node, EState *estate, int eflags)
285285
i = 0;
286286
foreach(vtl, node->values_lists)
287287
{
288-
List *exprs = castNode(List, lfirst(vtl));
288+
List *exprs = lfirst_node(List, vtl);
289289

290290
scanstate->exprlists[i] = exprs;
291291

src/backend/optimizer/util/paramassign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ process_subquery_nestloop_params(PlannerInfo *root, List *subplan_params)
431431

432432
foreach(lc, subplan_params)
433433
{
434-
PlannerParamItem *pitem = castNode(PlannerParamItem, lfirst(lc));
434+
PlannerParamItem *pitem = lfirst_node(PlannerParamItem, lc);
435435

436436
if (IsA(pitem->item, Var))
437437
{

src/backend/parser/parse_clause.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,7 @@ transformWindowDefinitions(ParseState *pstate,
28072807
(errcode(ERRCODE_WINDOWING_ERROR),
28082808
errmsg("RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"),
28092809
parser_errposition(pstate, windef->location)));
2810-
sortcl = castNode(SortGroupClause, linitial(wc->orderClause));
2810+
sortcl = linitial_node(SortGroupClause, wc->orderClause);
28112811
sortkey = get_sortgroupclause_expr(sortcl, *targetlist);
28122812
/* Find the sort operator in pg_amop */
28132813
if (!get_ordering_op_properties(sortcl->sortop,

src/backend/parser/parse_utilcmd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,7 +2424,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
24242424
/* Make sure referenced column exists. */
24252425
foreach(columns, cxt->columns)
24262426
{
2427-
column = castNode(ColumnDef, lfirst(columns));
2427+
column = lfirst_node(ColumnDef, columns);
24282428
if (strcmp(column->colname, key) == 0)
24292429
{
24302430
found = true;
@@ -2462,7 +2462,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
24622462

24632463
foreach(inher, cxt->inhRelations)
24642464
{
2465-
RangeVar *inh = castNode(RangeVar, lfirst(inher));
2465+
RangeVar *inh = lfirst_node(RangeVar, inher);
24662466
Relation rel;
24672467
int count;
24682468

@@ -4088,7 +4088,7 @@ transformPartitionBound(ParseState *pstate, Relation parent,
40884088
duplicate = false;
40894089
foreach(cell2, result_spec->listdatums)
40904090
{
4091-
Const *value2 = castNode(Const, lfirst(cell2));
4091+
Const *value2 = lfirst_node(Const, cell2);
40924092

40934093
if (equal(value, value2))
40944094
{
@@ -4267,7 +4267,7 @@ validateInfiniteBounds(ParseState *pstate, List *blist)
42674267

42684268
foreach(lc, blist)
42694269
{
4270-
PartitionRangeDatum *prd = castNode(PartitionRangeDatum, lfirst(lc));
4270+
PartitionRangeDatum *prd = lfirst_node(PartitionRangeDatum, lc);
42714271

42724272
if (kind == prd->kind)
42734273
continue;

src/backend/partitioning/partbounds.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ get_non_null_list_datum_count(PartitionBoundSpec **boundspecs, int nparts)
452452

453453
foreach(lc, boundspecs[i]->listdatums)
454454
{
455-
Const *val = castNode(Const, lfirst(lc));
455+
Const *val = lfirst_node(Const, lc);
456456

457457
if (!val->constisnull)
458458
count++;
@@ -513,7 +513,7 @@ create_list_bounds(PartitionBoundSpec **boundspecs, int nparts,
513513

514514
foreach(c, spec->listdatums)
515515
{
516-
Const *val = castNode(Const, lfirst(c));
516+
Const *val = lfirst_node(Const, c);
517517

518518
if (!val->constisnull)
519519
{
@@ -3014,7 +3014,7 @@ check_new_partition_bound(char *relname, Relation parent,
30143014

30153015
foreach(cell, spec->listdatums)
30163016
{
3017-
Const *val = castNode(Const, lfirst(cell));
3017+
Const *val = lfirst_node(Const, cell);
30183018

30193019
overlap_location = val->location;
30203020
if (!val->constisnull)
@@ -3399,7 +3399,7 @@ make_one_partition_rbound(PartitionKey key, int index, List *datums, bool lower)
33993399
i = 0;
34003400
foreach(lc, datums)
34013401
{
3402-
PartitionRangeDatum *datum = castNode(PartitionRangeDatum, lfirst(lc));
3402+
PartitionRangeDatum *datum = lfirst_node(PartitionRangeDatum, lc);
34033403

34043404
/* What's contained in this range datum? */
34053405
bound->kind[i] = datum->kind;
@@ -4103,7 +4103,7 @@ get_qual_for_list(Relation parent, PartitionBoundSpec *spec)
41034103
*/
41044104
foreach(cell, spec->listdatums)
41054105
{
4106-
Const *val = castNode(Const, lfirst(cell));
4106+
Const *val = lfirst_node(Const, cell);
41074107

41084108
if (val->constisnull)
41094109
list_has_null = true;
@@ -4358,8 +4358,8 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
43584358
Datum test_result;
43594359
bool isNull;
43604360

4361-
ldatum = castNode(PartitionRangeDatum, lfirst(cell1));
4362-
udatum = castNode(PartitionRangeDatum, lfirst(cell2));
4361+
ldatum = lfirst_node(PartitionRangeDatum, cell1);
4362+
udatum = lfirst_node(PartitionRangeDatum, cell2);
43634363

43644364
/*
43654365
* Since get_range_key_properties() modifies partexprs_item, and we
@@ -4440,11 +4440,11 @@ get_qual_for_range(Relation parent, PartitionBoundSpec *spec,
44404440
PartitionRangeDatum *ldatum_next = NULL,
44414441
*udatum_next = NULL;
44424442

4443-
ldatum = castNode(PartitionRangeDatum, lfirst(cell1));
4443+
ldatum = lfirst_node(PartitionRangeDatum, cell1);
44444444
if (lnext(spec->lowerdatums, cell1))
44454445
ldatum_next = castNode(PartitionRangeDatum,
44464446
lfirst(lnext(spec->lowerdatums, cell1)));
4447-
udatum = castNode(PartitionRangeDatum, lfirst(cell2));
4447+
udatum = lfirst_node(PartitionRangeDatum, cell2);
44484448
if (lnext(spec->upperdatums, cell2))
44494449
udatum_next = castNode(PartitionRangeDatum,
44504450
lfirst(lnext(spec->upperdatums, cell2)));

src/backend/rewrite/rewriteSearchCycle.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
307307
list_nth_oid(cte->ctecolcollations, i),
308308
0);
309309
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
310-
tle->resorigtbl = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigtbl;
311-
tle->resorigcol = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigcol;
310+
tle->resorigtbl = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigtbl;
311+
tle->resorigcol = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigcol;
312312
newq1->targetList = lappend(newq1->targetList, tle);
313313
}
314314

@@ -482,8 +482,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
482482
list_nth_oid(cte->ctecolcollations, i),
483483
0);
484484
tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
485-
tle->resorigtbl = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigtbl;
486-
tle->resorigcol = castNode(TargetEntry, list_nth(rte2->subquery->targetList, i))->resorigcol;
485+
tle->resorigtbl = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigtbl;
486+
tle->resorigcol = list_nth_node(TargetEntry, rte2->subquery->targetList, i)->resorigcol;
487487
newq2->targetList = lappend(newq2->targetList, tle);
488488
}
489489

src/backend/tcop/postgres.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ pg_rewrite_query(Query *query)
785785
*/
786786
foreach(lc, querytree_list)
787787
{
788-
Query *query = castNode(Query, lfirst(lc));
788+
Query *query = lfirst_node(Query, lc);
789789

790790
if (query->commandType != CMD_UTILITY)
791791
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy