Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe182d5

Browse files
committed
Improve castNode notation by introducing list-extraction-specific variants.
This extends the castNode() notation introduced by commit5bcab11 toprovide, in one step, extraction of a list cell's pointer and coercion toa concrete node type. For example, "lfirst_node(Foo, lc)" is the sameas "castNode(Foo, lfirst(lc))". Almost half of the uses of castNodethat have appeared so far include a list extraction call, so this ispretty widely useful, and it saves a few more keystrokes compared to theold way.As with the previous patch, back-patch the addition of these macros topg_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
1 parentc0a493e commitbe182d5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

‎src/include/nodes/pg_list.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,32 @@ list_length(const List *l)
106106
#definelfirst(lc)((lc)->data.ptr_value)
107107
#definelfirst_int(lc)((lc)->data.int_value)
108108
#definelfirst_oid(lc)((lc)->data.oid_value)
109+
#definelfirst_node(type,lc)castNode(type, lfirst(lc))
109110

110111
#definelinitial(l)lfirst(list_head(l))
111112
#definelinitial_int(l)lfirst_int(list_head(l))
112113
#definelinitial_oid(l)lfirst_oid(list_head(l))
114+
#definelinitial_node(type,l)castNode(type, linitial(l))
113115

114116
#definelsecond(l)lfirst(lnext(list_head(l)))
115117
#definelsecond_int(l)lfirst_int(lnext(list_head(l)))
116118
#definelsecond_oid(l)lfirst_oid(lnext(list_head(l)))
119+
#definelsecond_node(type,l)castNode(type, lsecond(l))
117120

118121
#definelthird(l)lfirst(lnext(lnext(list_head(l))))
119122
#definelthird_int(l)lfirst_int(lnext(lnext(list_head(l))))
120123
#definelthird_oid(l)lfirst_oid(lnext(lnext(list_head(l))))
124+
#definelthird_node(type,l)castNode(type, lthird(l))
121125

122126
#definelfourth(l)lfirst(lnext(lnext(lnext(list_head(l)))))
123127
#definelfourth_int(l)lfirst_int(lnext(lnext(lnext(list_head(l)))))
124128
#definelfourth_oid(l)lfirst_oid(lnext(lnext(lnext(list_head(l)))))
129+
#definelfourth_node(type,l)castNode(type, lfourth(l))
125130

126131
#definellast(l)lfirst(list_tail(l))
127132
#definellast_int(l)lfirst_int(list_tail(l))
128133
#definellast_oid(l)lfirst_oid(list_tail(l))
134+
#definellast_node(type,l)castNode(type, llast(l))
129135

130136
/*
131137
* Convenience macros for building fixed-length lists
@@ -204,6 +210,7 @@ extern ListCell *list_nth_cell(const List *list, int n);
204210
externvoid*list_nth(constList*list,intn);
205211
externintlist_nth_int(constList*list,intn);
206212
externOidlist_nth_oid(constList*list,intn);
213+
#definelist_nth_node(type,list,n)castNode(type, list_nth(list, n))
207214

208215
externboollist_member(constList*list,constvoid*datum);
209216
externboollist_member_ptr(constList*list,constvoid*datum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp