diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-04-10 13:51:29 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-04-10 13:51:53 -0400 |
commit | 8f0530f58061b185dc385df42e62d78a18d4ae3e (patch) | |
tree | 63d038ae4012dcdcff3b556dde4c654959f8448e /src/backend/nodes/nodeFuncs.c | |
parent | 56dd8e85c40fef3e3c2c10afa186ee30416ec507 (diff) | |
download | postgresql-8f0530f58061b185dc385df42e62d78a18d4ae3e.tar.gz postgresql-8f0530f58061b185dc385df42e62d78a18d4ae3e.zip |
Improve castNode notation by introducing list-extraction-specific variants.
This extends the castNode() notation introduced by commit 5bcab1114 to
provide, in one step, extraction of a list cell's pointer and coercion to
a concrete node type. For example, "lfirst_node(Foo, lc)" is the same
as "castNode(Foo, lfirst(lc))". Almost half of the uses of castNode
that have appeared so far include a list extraction call, so this is
pretty widely useful, and it saves a few more keystrokes compared to the
old way.
As with the previous patch, back-patch the addition of these macros to
pg_list.h, so that the notation will be available when back-patching.
Patch by me, after an idea of Andrew Gierth's.
Discussion: https://postgr.es/m/14197.1491841216@sss.pgh.pa.us
Diffstat (limited to 'src/backend/nodes/nodeFuncs.c')
-rw-r--r-- | src/backend/nodes/nodeFuncs.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index 4149e9fd1c9..3e8189ced36 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -111,7 +111,7 @@ exprType(const Node *expr) if (!qtree || !IsA(qtree, Query)) elog(ERROR, "cannot get type for untransformed sublink"); - tent = castNode(TargetEntry, linitial(qtree->targetList)); + tent = linitial_node(TargetEntry, qtree->targetList); Assert(!tent->resjunk); type = exprType((Node *) tent->expr); if (sublink->subLinkType == ARRAY_SUBLINK) @@ -324,7 +324,7 @@ exprTypmod(const Node *expr) if (!qtree || !IsA(qtree, Query)) elog(ERROR, "cannot get type for untransformed sublink"); - tent = castNode(TargetEntry, linitial(qtree->targetList)); + tent = linitial_node(TargetEntry, qtree->targetList); Assert(!tent->resjunk); return exprTypmod((Node *) tent->expr); /* note we don't need to care if it's an array */ @@ -382,7 +382,7 @@ exprTypmod(const Node *expr) return -1; /* no point in trying harder */ foreach(arg, cexpr->args) { - CaseWhen *w = castNode(CaseWhen, lfirst(arg)); + CaseWhen *w = lfirst_node(CaseWhen, arg); if (exprType((Node *) w->result) != casetype) return -1; @@ -809,7 +809,7 @@ exprCollation(const Node *expr) if (!qtree || !IsA(qtree, Query)) elog(ERROR, "cannot get collation for untransformed sublink"); - tent = castNode(TargetEntry, linitial(qtree->targetList)); + tent = linitial_node(TargetEntry, qtree->targetList); Assert(!tent->resjunk); coll = exprCollation((Node *) tent->expr); /* collation doesn't change if it's converted to array */ @@ -1054,7 +1054,7 @@ exprSetCollation(Node *expr, Oid collation) if (!qtree || !IsA(qtree, Query)) elog(ERROR, "cannot set collation for untransformed sublink"); - tent = castNode(TargetEntry, linitial(qtree->targetList)); + tent = linitial_node(TargetEntry, qtree->targetList); Assert(!tent->resjunk); Assert(collation == exprCollation((Node *) tent->expr)); } @@ -2058,7 +2058,7 @@ expression_tree_walker(Node *node, /* we assume walker doesn't care about CaseWhens, either */ foreach(temp, caseexpr->args) { - CaseWhen *when = castNode(CaseWhen, lfirst(temp)); + CaseWhen *when = lfirst_node(CaseWhen, temp); if (walker(when->expr, context)) return true; @@ -3308,7 +3308,7 @@ raw_expression_tree_walker(Node *node, /* we assume walker doesn't care about CaseWhens, either */ foreach(temp, caseexpr->args) { - CaseWhen *when = castNode(CaseWhen, lfirst(temp)); + CaseWhen *when = lfirst_node(CaseWhen, temp); if (walker(when->expr, context)) return true; @@ -3807,7 +3807,7 @@ planstate_walk_subplans(List *plans, foreach(lc, plans) { - SubPlanState *sps = castNode(SubPlanState, lfirst(lc)); + SubPlanState *sps = lfirst_node(SubPlanState, lc); if (walker(sps->planstate, context)) return true; |