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

Commitff93980

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 parent649cd90 commitff93980

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
@@ -115,26 +115,32 @@ list_length(const List *l)
115115
#definelfirst(lc)((lc)->data.ptr_value)
116116
#definelfirst_int(lc)((lc)->data.int_value)
117117
#definelfirst_oid(lc)((lc)->data.oid_value)
118+
#definelfirst_node(type,lc)castNode(type, lfirst(lc))
118119

119120
#definelinitial(l)lfirst(list_head(l))
120121
#definelinitial_int(l)lfirst_int(list_head(l))
121122
#definelinitial_oid(l)lfirst_oid(list_head(l))
123+
#definelinitial_node(type,l)castNode(type, linitial(l))
122124

123125
#definelsecond(l)lfirst(lnext(list_head(l)))
124126
#definelsecond_int(l)lfirst_int(lnext(list_head(l)))
125127
#definelsecond_oid(l)lfirst_oid(lnext(list_head(l)))
128+
#definelsecond_node(type,l)castNode(type, lsecond(l))
126129

127130
#definelthird(l)lfirst(lnext(lnext(list_head(l))))
128131
#definelthird_int(l)lfirst_int(lnext(lnext(list_head(l))))
129132
#definelthird_oid(l)lfirst_oid(lnext(lnext(list_head(l))))
133+
#definelthird_node(type,l)castNode(type, lthird(l))
130134

131135
#definelfourth(l)lfirst(lnext(lnext(lnext(list_head(l)))))
132136
#definelfourth_int(l)lfirst_int(lnext(lnext(lnext(list_head(l)))))
133137
#definelfourth_oid(l)lfirst_oid(lnext(lnext(lnext(list_head(l)))))
138+
#definelfourth_node(type,l)castNode(type, lfourth(l))
134139

135140
#definellast(l)lfirst(list_tail(l))
136141
#definellast_int(l)lfirst_int(list_tail(l))
137142
#definellast_oid(l)lfirst_oid(list_tail(l))
143+
#definellast_node(type,l)castNode(type, llast(l))
138144

139145
/*
140146
* Convenience macros for building fixed-length lists
@@ -209,6 +215,7 @@ extern List *list_truncate(List *list, int new_size);
209215
externvoid*list_nth(constList*list,intn);
210216
externintlist_nth_int(constList*list,intn);
211217
externOidlist_nth_oid(constList*list,intn);
218+
#definelist_nth_node(type,list,n)castNode(type, list_nth(list, n))
212219

213220
externboollist_member(constList*list,constvoid*datum);
214221
externboollist_member_ptr(constList*list,constvoid*datum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp